vbYesNo not working with DoCmd

B

Bart

I am calling the following procedure a module to
print/save a report but it always runs the DoCmd even if
the user chooses vbNo. Any suggestions?

Public Function printoptions()
'This functions provides the user with the option to print
and save the report (letter)

MsgBox "Do you want to print the letter?", vbYesNo
If vbYes Then
DoCmd.PrintOut acPrintAll
End If

MsgBox "Do you want to save the letter?", vbYesNo
If vbYes Then
DoCmd.OutputTo acOutputReport, , acFormatRTF
Else
DoCmd.Close
End If

End Function

Thanks for your help.

Bart
 
M

Marshall Barton

Bart said:
I am calling the following procedure a module to
print/save a report but it always runs the DoCmd even if
the user chooses vbNo. Any suggestions?

Public Function printoptions()
'This functions provides the user with the option to print
and save the report (letter)

MsgBox "Do you want to print the letter?", vbYesNo
If vbYes Then
DoCmd.PrintOut acPrintAll
End If

MsgBox "Do you want to save the letter?", vbYesNo
If vbYes Then
DoCmd.OutputTo acOutputReport, , acFormatRTF
Else
DoCmd.Close
End If

End Function


It's the MsgBox function that returns the vbYes value.

Dim response As Integer
response = MsgBox("Do you want to print the letter?", _
, vbYesNo)
If response = vbYes Then
. . .
 

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