Closing a report



Ok, I hope I can make this clear. when I open the form using the
DoCmd.OpenReport command and the report has data,everything is fine. If the
report is empty and the line "Cancel = True" is in the NoData area, it
crashes. Something about DoCmd.OpenReport and pressing Cancel. I'm trying
to use a combobox to select the information to open the report and if the
report is empty, alert me and exit. Anyone have any ideas? I hope I've
made this understandable. Any help will be appreciated.

PS. works if CANCEL = True isn't present but runs the messagebox twice and
opens the blank report if no data.

-----Click command from combobox form-----

Private Sub cmdFindPMOK_Click()

Dim stDocName As String
stDocName = "rptChargeVerificationPM"
DoCmd.OpenReport stDocName, acViewPreview

End Sub

---Events inside the report------

Option Compare Database
Option Explicit
Dim ND As Boolean

Private Sub Report_Close()
Dim strSql As String
Dim strID As String

If Not ND Then
MsgBox ("Updated!!")
strID = Me!CardHolderIDtxt
strSql = "UPDATE tblChargeVerification SET Submitted = True WHERE Submitted
= False AND CardHolderID = '" & strID & "';"
DBEngine(0)(0).Execute strSql, dbFailOnError
End If

End Sub

Private Sub Report_NoData(Cancel As Integer)

ND = True
MsgBox ("There are no items to Print")

End Sub

Al Camp

You wrote...
and the line "Cancel = True" is in the NoData area, it crashes.
Where are you putting the Cancel=True? In the NoData property box? You
should have EventProcedure entered in there, and the Cancel=True in the
NoData event of the form's module.
Here's the sample from OnNoData in Help...

Private Sub Report_NoData(Cancel As Integer)
MsgBox "The report has no data." _
& "@Printing the report is canceled. " _
& "@Check the source of data for the report to make sure you " _
& "entered the correct criteria (for example, a valid range " _
& "of dates).", vbOKOnly + vbInformation
Cancel = True
End Sub

But... the best solution is to not allow reports without data to be
selected from your combo in the first place. Use the query behind your
combo to limit the list to only items that have reportable data. IMHO...
better to prevent an error, that to code to correct one.
Al Camp
Candia Computer Consulting - Candia NH

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

Similar Threads