MsgBox Macro

  • Thread starter Thread starter Johnny
  • Start date Start date
J

Johnny

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.
 
Johnny,

It is not clear why you would be doing stuff within VBA code, and then
jumping out to a macro for your mesagebox. This type of structure
should do the trick...

If IsNull(Me!cbxWorkCenter#) Then
MsgBox "No ClassCode# entered"
Else
DoCmd.OpenReport "rptMFG QC Scrap Detail by WorkCenter#",
acViewPreview
End If

Another thing to explore would be the No Data event of the report itself.

By the way, as an aside, it is not a good idea to use a # as part of the
name of a field or control or database object.
 
Back
Top