Trying to Open Dialog Box with VB

jlr573

New member
Local time
Today, 17:03
Joined
Aug 9, 2010
Messages
4
I'm trying to open a dialog box using VB code and the vbyesnocancel
i want a report to open when the user clicks yes and when they click no i want to go head a print the report they are on.

Private Sub Command30_Click()
MsgBox ("Would You Like To Attach a Material Sheet?"), vbYesNoCancel
If MsgBox = vbYes Then DoCmd.OpenReport ("rptMaterialSheet"), acViewReport, , , acDialog
If MsgBox = vbNo Then DoCmd.PrintOut , , , acHigh
End Sub

But i get the folowing error

Argument Not Optional

Please Help!!
 
For one thing you have an input variable outside your paranthesis. Try something more like:

Private Sub Command30_Click()
Dim iResponse As Integer

iResponse = MsgBox("Would You Like To Attach a Material Sheet?", vbYesNoCancel)
If iResponse = vbYes Then
DoCmd.OpenReport ("rptMaterialSheet"), acViewReport, , , acDialog
ElseIf iResponse = vbNo Then
DoCmd.PrintOut , , , acHigh
Else
'User canceled
End If

End Sub
 
Thanks this works great!
I do have another question though. How do i get the code to print the report
"rptMaterialSheet" once it opens and also print the report that the Command30 button is on?
 

Users who are viewing this thread

Back
Top Bottom