I currently display the Common Dialog box for Printer. How can you catch the button that was pressed. Ie: did the user select the "OK" or the "Cancel"
thanks in advance
Printable View
I currently display the Common Dialog box for Printer. How can you catch the button that was pressed. Ie: did the user select the "OK" or the "Cancel"
thanks in advance
Use :
CommonDialog.CancelError = True
If the user clicks on Cancel, the Dialog will return an error. Else it returns 0
Code:On Error Resume Next
CommonDialog1.CancelError = True
CommonDialog1.Action = 6 'I think
If Err = 0 then 'User clicked OK
'Do your printing here
ElseIf Err = 32755 'User clicked Cancel
'Do NOT print
End If
Try this code. Make a Form with a CommonDialog and put the following code into a CommandButton.
Code:On Error Resume Next
'Generate an error when Cancel is selected
CommonDialog1.CancelError = True
CommonDialog1.ShowPrinter
If Err <> 32755 Then
'User Pressed OK
Print "You pressed OK"
Else
'User Pressed Cancel
Print "You pressed Cancel"
End If