Options on a MsgBox (1 Viewer)

D

D B Lawson

Guest
I have a message box linked to a command button which prints a report. I want to give the user the option to "OK" (proceed and print the report) and "Cancel" (not proceed. I have managed to get the two boxes to appear in the MsgBox but both print the report. How do I make the "Cancel" button work?
 

Carol

Registered User.
Local time
Today, 12:22
Joined
Jan 15, 2000
Messages
280
In the On Click in the properties for the cancel button, make an Event Procedure and have the following:
Private Sub Cancel_Click()
On Error GoTo Cancel_Click_Err

DoCmd.Close acForm, "MessageBoxForm"


Cancel_Click_Exit:
Exit Sub

Cancel_Click_Err:
MsgBox Error$
Resume Cancel_Click_Exit

End Sub
 

R. Hicks

AWF VIP
Local time
Today, 06:22
Joined
Dec 23, 1999
Messages
619
I think this is what you need. This code is using the On Click event of your command button.

Change "cmdYourButton" to the name of your command button.

Private Sub cmdYourButton_Click()
Dim strMsg1 As String, strTitle1 As String
Dim strMsg2 As String, strTitle2 As String
Dim intResponse As Integer
strMsg1 = "Do you wish to Print the Report?"
strTitle1 = "Print Report?"
strMsg2 = "You Canceled the Print Operation."
strTitle2 = "Cancel Print"

intResponse = MsgBox(strMsg1, vbOKCancel, strTitle1)
If intResponse = vbOK Then
'Place your code here to open the report
Else
MsgBox strMsg2, vbOKOnly, strTitle2
'....Do whatever if Cancel is chosen
End If
End Sub

HTH
RDH

[This message has been edited by R. Hicks (edited 04-29-2000).]
 
R

Richard

Guest
To D Lawson:
Here's a simple piece of code which may help
you:
Use the onClick event property of the command
button that opens your report and insert the
following code:
on error resume next
Dim message as string,reply as integer
Message ="Print Report@'OK' to _print@'CANCEL'to return"
reply =Msgbox(message,vbOkCancel)
if reply =vbok then
doCmd.openReport "reportname",acNormal
end if
end sub
Richard
 

Users who are viewing this thread

Top Bottom