Checking if record exists for a report

  • Thread starter Thread starter Juan
  • Start date Start date
J

Juan

I been having problems with a report. I have this report
which its information comes from a query. The query asks
the user to enter the primary key record they are looking
for. The problem I have is that if they enter a key that
does not exist then the report is printed empty. I would
like to check the input that the user entered to see first
if it exists. If it does then to go ahead and print the
report. Else if it does not exist, then tell the user,
and cancel the printing. Is there any way I can retrieve
what the user entered before it immediately prints the
report? the only command I am using in VBA is :

DoCmd.OpenReport rs![Argument], acViewNormal

So I would probably would have to break all this into
maybe more steps.

Thank you
 
the easiest way i can think of is to use the report's
OnNoData event, as


Private Sub Report_NoData(Cancel As Integer)

Cancel = True
MsgBox "There is no data for the key you entered."

End Sub

in Help, look up events in the Index, then click on NoData
from the list, and read the NoData Event section. click on
the Event Procedures subheader in that section, then
Display in the dialog box, to get more info on how the
event works.

hth
 
You have a number of options
1. Use the OnNoData event of the report to display a message, then
cancle the report

2. Your code runs something like this at the moment
GetPrimaryKey
PassPrimaryKeyToReport
PrintReport

Instead try
GetPrimaryKey
ValidateKey
If KeyValid then
Pass KeyToReport
PrintReport
endif

The simplest way to check the key's validity is to use one of the
Domain Aggregate functions. Look for them in the help files
Most will return #Null# if the key does not exist, and some other
value if it does.

HTH
 
Back
Top