Report opening without record (1 Viewer)

moi

Member
Local time
Tomorrow, 01:47
Joined
Jan 10, 2024
Messages
235
I need help of my report, I based my report to a query, and i wanted if no record to display, a message popup "no records to display", close the msgbox, focus will go back to "printmgr" form control where my selection starts..

thank you for any help..
 

Gasman

Enthusiastic Amateur
Local time
Today, 18:47
Joined
Sep 21, 2011
Messages
14,438
Use Dcount() on the report criteria before opening report.
Check record count of source on load of report. Exit report if zero.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:47
Joined
Feb 19, 2002
Messages
43,472
Use the OnNoData event of the report to display your message.

You may also need to add error trapping in the event that opens the report to catch the 2501 error.
 
  • Like
Reactions: moi

tvanstiphout

Active member
Local time
Today, 10:47
Joined
Jan 22, 2016
Messages
249
Use Dcount() on the report criteria before opening report.
Check record count of source on load of report. Exit report if zero.
That would require the db to be queried twice - unnecessary in light of the Report_NoData event.
 

moi

Member
Local time
Tomorrow, 01:47
Joined
Jan 10, 2024
Messages
235
Use the OnNoData event of the report to display your message.

You may also need to add error trapping in the event that opens the report to catch the 2501 error.
Hi Pat,

Would you please expand, as a beginner, my knowledge is very limited.. Where is the "OnNoData" event, and the error "2501".

Appreciate your kind help on both of these.. Any link where i can get a good demo/sample, please.

Thank you.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 18:47
Joined
Feb 19, 2013
Messages
16,663
Where is the "OnNoData" event
where all events are - in the property sheet events tab
1714522201478.png


and the error "2501".

this error can apply to many things (just google 'vba error 2501'). But you should have a message as well which tells you where to find it. Since you are talking about reports, my guess would be this link will be indicative
 

moi

Member
Local time
Tomorrow, 01:47
Joined
Jan 10, 2024
Messages
235
where all events are - in the property sheet events tab
View attachment 113942



this error can apply to many things (just google 'vba error 2501'). But you should have a message as well which tells you where to find it. Since you are talking about reports, my guess would be this link will be indicative
Thanks CJ_London, I will check the link and see if i get to work.
 

tvanstiphout

Active member
Local time
Today, 10:47
Joined
Jan 22, 2016
Messages
249
2501 is not really an error. That's why in the Northwind 2 Developer Edition template's central error handler we write:
If lngError = 2501 Then Exit Sub '2501 = The OpenForm or OpenReport action was canceled. Not really an error.
 

Users who are viewing this thread

Top Bottom