Command button plus message

C

Charlie

Hi,

I have a command button which prints a report. I want to include a message
which will pop up if certain fields are not entered within the form or
subforms but not if they are complete. The current code is:
Private Sub Command38_Click()
On Error GoTo Err_Command38_Click

Dim stDocName As String

stDocName = "Order"
DoCmd.OpenReport stDocName, acNormal

Exit_Command38_Click:
Exit Sub

Err_Command38_Click:
MsgBox Err.Description
Resume Exit_Command38_Click

End Sub

Many thanks

Charlotte
 
J

Jeff Boyce

Charlotte

So, you're saying that if, perhaps, there's nothing in your control
txtFillMeIn, you want to NOT run the report?

If so, then before running the OpenReport command, you'd need to test
txtFillMeIn to see if there's a (valid) value, right?

Take a look at Access HELP on the If ... Else ... command block to help with
this.

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 
J

John W. Vinson

Hi,

I have a command button which prints a report. I want to include a message
which will pop up if certain fields are not entered within the form or
subforms but not if they are complete.

What do you want to do if they're not complete? Cancel launching the report,
just warn the user and go on, what?

The code might be

Private Sub Command38_Click()
On Error GoTo Err_Command38_Click

Dim stDocName As String
Dim iAns As Integer

stDocName = "Order"
If Me.Dirty = True Then Me.Dirty = False ' write record to disk
If IsNull(Me!requiredcontrol) Then
iAns = MsgBox("requiredcontrol isn't filled in!" _
& " Click OK to print anyway, Cancel to skip it", vbOKCancel)
If iAns = vbOK Then
DoCmd.OpenReport stDocName, acNormal
End If

Exit_Command38_Click:
Exit Sub

Err_Command38_Click:
MsgBox Err.Description
Resume Exit_Command38_Click

End Sub

Many thanks

Charlotte
 

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