Question : "Save As" dialog box - Capture "Cancel" button click event.

I'm using VB 2008 Express & Access 2003.

I have a form with two buttons that gives the user options to print, hardcopy or file. I'm using the code shown below in the btnPrinttoFile_Click event. The code first changes the default printer from the "local" printer to Microsoft Office Document Image Writer (to file). A "Save As" dialog box appears requesting the filename & save location and once the "Save" button is clicked the report is saved to file and the default printer is reset to "local" printer. All good, however, if the user clicks the "Cancel" button in the "Save As" dialog box, the program stops responding.

The "Save As" dialog box is being generated by WIndows XP.  How do I capture the "Cancel" button click event?

Thanks for any help.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
Dim Adb1 As New Microsoft.Office.Interop.Access.Application
        Dim wsh As Object
        Dim printer1 As String = "HP Officejet 6500 E709a Series"
        Dim printer2 As String = "Microsoft Office Document Image Writer"
        wsh = CreateObject("WScript.Network")
        wsh.SetDefaultPrinter(printer2)
 
        Dim numWorkOrdVL1 As Integer
        numWorkOrdVL1 = txtQCCOAL1VL.Text
        Adb1.OpenCurrentDatabase("C:\DB\Main Application.mdb")
        Adb1.DoCmd.OpenReport("rptQCCOAL1VL", AcView.acViewNormal, , "WorkOrd=" & numWorkOrdVL1)
        Adb1.CloseCurrentDatabase()
        Adb1.Quit()
 
        wsh.SetDefaultPrinter(printer1)

Answer : "Save As" dialog box - Capture "Cancel" button click event.

Finally decided to use Try, Catch exception handling to solve the problem. The Save As dialog box cancel button caused the OpenReport to cancel, an exception that the Catch revealed. Adding Exit Sub to the Catch returned control to the application.
Random Solutions  
 
programming4us programming4us