Where to put a dcount when have query parameters (1 Viewer)

lehcarrodan

Registered User.
Local time
Today, 01:58
Joined
Feb 20, 2017
Messages
11
I'd like to open a report that requires parameter input but only open the report if the query returns values. (It's a sales report)

So I know I can use
If DCount("*", "qryWhatever") > 0 Then ...

but then it seems I need to input the parameters twice? Can I have this check done by the query itself?

Thanks for the help, hope this makes sense! I'm new here haha
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 01:58
Joined
Aug 30, 2003
Messages
36,118
You can use the no data event of the report to stop it if there are no records:

Cancel = True

though you have to trap for the 2501 error in the code that opens the report. To your question, most of us would use a form to gather the user input, and both your DCount() and query could get them from there.
 

lehcarrodan

Registered User.
Local time
Today, 01:58
Joined
Feb 20, 2017
Messages
11
Thank you, thank you! I will make a form for input. However what do you mean trap for 2501 error? How do I do that.
 

lehcarrodan

Registered User.
Local time
Today, 01:58
Joined
Feb 20, 2017
Messages
11
Okay prefect! Just so I understand what's happening.. There's an automatic error in this case 2501 that occurs when there's no data returned? And instead of displaying that message I'm putting my own?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 01:58
Joined
Aug 30, 2003
Messages
36,118
More accurately, the error is returned when the opening of the report is cancelled. Yes, you'd put your own message there.
 

Users who are viewing this thread

Top Bottom