Full Version: Chosing A Report To Display Based On Yes/no Box Status
UtterAccess Discussion Forums > Microsoft® Access > Access Q and A
kjohnson
Hi all,

I was wondering if it is possible to include code into one of my command buttons to have it look at the status of a yes/no option for which report to open. Currently, I have a report which summarizes all animals in a given date range. I would like to add a checkbox that when activated will open a different report that has just the summation of the numbers (# of procedures, total amount, etc) versus when the checkbox is not activated - then it would open the by-animal summary.

Is that even possible? Or should I just make another command button to open the different report.

Something like,

If [Forms]![Welcome]![CheckSum] = True then DoCmd.OpenReport "QRptAll" Else Do.Cmd.OpenReport "QRptSummary" End If

?
Alan_G
Hi

You're pretty much there, it just needs splitting onto different lines -

CODE
If [Forms]![Welcome]![CheckSum] = True Then
   DoCmd.OpenReport "QRptAll"
   Else
   DoCmd.OpenReport "QRptSummary"
End If
kjohnson
Awesome, that worked. Now here's another issue:

I can't get my report to count the procedures based on the status of the Non-Clinical checkbox. It's able to sum the total cost with "=Sum(IIf([Non_Clinical]=No,[Cost],0)). Why won't it work with =Count in place of =Sum?
Alan_G
Hi

Are you wanting a count of both alternative values for the checkbox, ie Yes and No ? You can't just substitute Count() directly for Sum() in your expression as it doesn't 'know' what to count wink.gif

If you want the count of both values, you'd need two textboxes with their respective control sources set to

=Count([Non_Clinical] = False)

and

=Count([Non_Clinical] = True)
kjohnson
Ah, I see. I think I've inhaled too much isoflurane this morning during surgeries. dazed.gif Thank you so much.
kjohnson
QUOTE (kjohnson @ May 14 2012, 04:51 PM) *
Ah, I see. I think I've inhaled too much isoflurane this morning during surgeries. dazed.gif Thank you so much.


I replied too quickly. It's still counting all procedures. *Head hits desk*
Alan_G
Hi

QUOTE
I think I've inhaled too much isoflurane this morning during surgeries


Send some over here - I've had toothache for the last two days and could do with a quick blast laugh.gif

You could always do it in just one textbox if that's what you're wanting with something like

CODE
= "Number of Non-Clinicals: " & Count([Non_Clinical] = False) & Chr(13) & Chr(10) & "Number of Clinicals: " & Count([Non_Clinical] = True)
kjohnson
What are the Chr(13) & Chr(10) for?
Alan_G
Hi

QUOTE
What are the Chr(13) & Chr(10) for?


To put the two text strings on different lines in the same textbox, so it should come out looking like

Number of Non-Clinicals: 53
Number of Clinicals: 121

or whatever the numbers should be
kjohnson
Neato! So... it's still counting all records, but when I put Sum instead of Count, it kicks back the right number of records, just with a negative sign. I don't understand that....
Alan_G
Hi

Try this

CODE
="Number of Non-Clinicals: " & Abs(Sum([Non_Clinical])) & Chr(13) & Chr(10) & "Number of Clinicals: " &  Abs(Sum([Non_Clinical]=0))


I may have them the wrong way round - and still untested!!!
kjohnson
Okay, that one worked. I was able to get this to work too, I just haven't been out of surgery until now:

For Clinical:
CODE
=Count(IIf([Non_Clinical]=False,0))


For Non-Clinical:
CODE
=Count(IIf([Non_Clinical]=True,0))


Just for future reference. wink.gif And thank you for your help!
Alan_G
Hi

Thanks for posting your solution and glad you got it working thumbup.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.