Coding for a Message Box Macro

J

Johnny

I may have posted this question earlier in the wrong place under the macro
discussions, so forgive me for trying again since I've not seen any responses:

This should be fairly simple, but never for me. All I want to do is have my
MsgBox macro to pop up and say "No data for this report". My macro works
fine, but I cannot figure out the code for where I need it to pop up.

The basis is a simple form with text dates beginning and ending, plus two
drop down boxes with WorkCenter# OR ClassCode# (just basic 4 digit numbers
each). Then there is the option to print a report based on the criteria I
select. One report button for ClassCode# and a second button for
WorkCenter#. If the operator fails to put in a ClassCode# (for instance),
then selects the ClassCode# report button, the macro message box should pop
up with the above statement. How and where would I insert that macro request
into the code of the form? I tried this, but no luck:

Private Sub Report_by_WorkCenter#_Click()
On Error GoTo Err_Report_by_WorkCenter#_Click

Dim stDocName As String

If IsNull(Me!cbxWorkCenter#) Then
DoCmd mcrMsgBox
Exit Sub
End If

stDocName = "rptMFG QC Scrap Detail by WorkCenter#"
DoCmd.OpenReport stDocName, acPreview

Exit_Report_by_WorkCenter#_Click:
Exit Sub

Err_Report_by_WorkCenter#_Click:
MsgBox Err.Description
Resume Exit_Report_by_WorkCenter#_Click

End Sub

Any suggestions is greatly appreciated.
 
K

Ken Warthen

Johnny

Open your report in design view and add an event procedure to the "On No
Data" event. You can use something like the following code for the event.

Private Sub Report_NoData(Cancel As Integer)

MsgBox "There is no data that matches the selected criteria." & vbCrLf &
"Please check the selected criteria.", vbOKOnly + vbCritical, "Invalid
Criteria"
Cancel = True

End Sub


Ken
 
J

Johnny

Ken,

You are totally awesome. Thank you so much for the solution to my problem.
Have a great day.
 

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


Top