I am really green when it comes to VB. I have written some code to print a report in Access 2007. When I press my command button, the print properties window comes up just like it should. If I select print in the print properties window, the code runs fine. But, if I select cancel, then I get a run time error. I am sure I am just missing some code. Could someone please fill in the blanks for me. Below is the code I am using.
Code:
CurrentDb.Execute mySQL, dbFailOnError
DoCmd.OpenReport "rptWorkOrder", acViewReport, "", "[WorkOrderNum]=[Forms]![frmIncompleteWO]![combo19]", acNormal
DoCmd.RunCommand acCmdPrint
DoCmd.Close acReport, "rptWorkOrder"
DoCmd.Close acForm, "frmIncompleteWO"
End Sub
Code:
CurrentDb.Execute mySQL, dbFailOnError
DoCmd.OpenReport "rptWorkOrder", acViewReport, "", "[WorkOrderNum]=[Forms]![frmIncompleteWO]![combo19]", acNormal
DoCmd.RunCommand acCmdPrint
DoCmd.Close acReport, "rptWorkOrder"
DoCmd.Close acForm, "frmIncompleteWO"
End Sub