From: Charlie on
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
From: Jeff Boyce on
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.

"Charlie" <Charlie(a)discussions.microsoft.com> wrote in message
news:D40912E1-065A-41A5-9C74-92C9B7FD9A60(a)microsoft.com...
> 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


From: John W. Vinson on
On Tue, 23 Mar 2010 13:26:01 -0700, Charlie
<Charlie(a)discussions.microsoft.com> wrote:

>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
--

John W. Vinson [MVP]