Report Count using Visual Basic

C

CLSWL

I have a form that "filters" a report.

It works fine but now I would like to have a message pop up anytime the
criteria entered has no results. Right now I get a report with no data.

How to I capture the amount of records using VB?

I run my report as follows:
DoCmd.OpenReport "repAssyNo", acViewPreview, , strMod & "AND" & strDraw1 &
"AND" & strDraw2, acWindowNormal
 
D

Duane Hookom

Normally this is handled in the Report's On No Data event property.

Private Sub Report_NoData(Cancel As Integer)
MsgBox "No records to report", _
vbOKOnly + vbInformation, "No Data"
Cancel = True
End Sub

You might also need to trap and ignore err.number 2501 in the code that
opens the report.
 
C

CLSWL

I did a simple message box in the Report's On No Data event property and it
works. The only thing is that it pops up twice and the the report pops up as
well.

Ideally I would like it to pop up once and then have the report not pop up
or close so quickly that no one sees.

Can I do that in the same On No Data event property code? What would I do.
I tried "DoCmd.Close Report" but that just gave an error because in my form's
code it's trying to open the report.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top