Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 4th, 2007, 11:31 AM
Authorized User
 
Join Date: Feb 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default Expression Builder

I'm building a report and I need to count the number of records [AppNum] where [MinInc1] is between 0 and 7 or [MinInc2] is between 0 and 7.

Any suggestions?
 
Old October 5th, 2007, 07:11 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

It sounds like you want to Count the number of AppNum (is that your PK?) if those conditions are met.

What you probably want to do is to create a check box on the Detail Section, and set Visible to No. Then on the Detail Section's On Format event, put this code (this assumes that there are no Nulls in the MinInc fields):

Dim nMinInc1 As Long
Dim nMinInc2 As Long
Dim b1 As Boolean
Dim b2 As Boolean

b2 = False
b1 = False

nMinInc1 = Me.MinInc1
nMinInc2 = Me.MinInc2

If nMinInc1 >= 0 And nMinInc1 >= 7 Then
   b1 = True
Else
   b1 = False
End If

If nMinInc2 >= 0 And nMinInc2 >= 7 Then
   b2 = True
Else
   b2 = False
End If

If b1 = True OR b2 = True Then
   Me.chkMins = True
Else
   Me.chkMins = False
End If

Then you can do this in a Textbox on the header or footer of the report:

=Sum(IIf([chkMins]=True, 1, 0))

You may have to play around with this, like

=Sum(IIf([chkMins]=Yes, 1, 0))
=Sum(IIf([chkMins]=1, 1, 0))
=Sum(IIf([chkMins]=-1, 1, 0))
=Sum(IIf([chkMins]<>0, 1, 0))

I am not sure which one it will pick up for a check box.

Okay, that is real brute force coding. Does someone have a much more elegant way of doing this? I know there must be.

HTH

mmcdonal
 
Old October 5th, 2007, 07:12 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Oops, I meant:

If nMinInc1 >= 0 And nMinInc1 <= 7 Then
   b1 = True
Else
   b1 = False
End If

If nMinInc2 >= 0 And nMinInc2 <= 7 Then
   b2 = True
Else
   b2 = False
End If


mmcdonal
 
Old October 5th, 2007, 07:18 AM
Authorized User
 
Join Date: Feb 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks. I'll give this a try.





Similar Threads
Thread Thread Starter Forum Replies Last Post
course builder youyou_hym Dreamweaver (all versions) 1 May 28th, 2008 03:09 AM
Message> in query expression <expression>. (Error ybg1 Access 5 July 15th, 2007 05:42 AM
Report in C++ Builder tiago C++ Programming 2 June 15th, 2006 12:29 PM
C++ Builder 6 - DBGrid rowin C++ Programming 0 April 13th, 2006 06:39 AM
C++ Builder 6 - Printing rowin C++ Programming 1 April 7th, 2006 02:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.