jtgarrison85
New member
- Local time
- Today, 13:44
- Joined
- Mar 10, 2023
- Messages
- 6
All - I can a form that has a button on it that exports an Invoice to a PDF file (code below).
The problem I'm having is that when the user clicks on the button, the Save dialog box pops up (normal). If they decide they don't want to do that operation and click Cancel, the Save box opens again.
Any help would be much appreciated.
CODE:
Private Sub cmdExportInvoiceToPDF_Click()
On Error GoTo Err_cmdExportInvoiceToPDF_Click
Dim OutFileName As String
Dim OutFile As String
Dim strFilter As String
Dim blnInvoiceType As Boolean
blnInvoiceType = DLookup("custPOVersionEnabled", "tblCustomerType", "custtypeID='" & InvoiceVendor & "'")
DoCmd.SetWarnings False 'Turn Off System Warnings
DoCmd.RunSQL ("UPDATE tblCurrentValues SET InvoiceNumber=" & Me![InvoiceNumber])
DoCmd.SetWarnings True 'Turn On System Warnings
OutFileName = "Project Invoice - " & InvoiceProjectNumber & " - " & InvoiceNumberText & ".pdf"
strFilter = ahtAddFilterItem(strFilter, "PDF Files (*.pdf)", "*.pdf")
OutFile = ahtCommonFileOpenSave(InitialDir:="", _
Filter:=strFilter, OpenFile:=False, FileName:=OutFileName, _
DialogTitle:="Save As", _
Flags:=ahtOFN_OVERWRITEPROMPT)
If blnInvoiceType = True Then
DoCmd.OutputTo acOutputReport, "rptProjectInvoicePDFVendorOrderVersion", acFormatPDF, OutFile, True
Else
DoCmd.OutputTo acOutputReport, "rptProjectInvoicePDFVendorNonOrderVersion", acFormatPDF, OutFile, True
End If
ShellExecuteA Application.hWndAccessApp, "open", OutFile, vbNullString, vbNullString, 1
Exit_cmdExportInvoiceToPDF_Click:
Exit Sub
Err_cmdExportInvoiceToPDF_Click:
If Err.Number = 2501 Then GoTo Exit_cmdExportInvoiceToPDF_Click
MsgBox Err.Number & " - " & Err.Description
Resume Exit_cmdExportInvoiceToPDF_Click
End Sub
Thanks
Jeff
The problem I'm having is that when the user clicks on the button, the Save dialog box pops up (normal). If they decide they don't want to do that operation and click Cancel, the Save box opens again.
Any help would be much appreciated.
CODE:
Private Sub cmdExportInvoiceToPDF_Click()
On Error GoTo Err_cmdExportInvoiceToPDF_Click
Dim OutFileName As String
Dim OutFile As String
Dim strFilter As String
Dim blnInvoiceType As Boolean
blnInvoiceType = DLookup("custPOVersionEnabled", "tblCustomerType", "custtypeID='" & InvoiceVendor & "'")
DoCmd.SetWarnings False 'Turn Off System Warnings
DoCmd.RunSQL ("UPDATE tblCurrentValues SET InvoiceNumber=" & Me![InvoiceNumber])
DoCmd.SetWarnings True 'Turn On System Warnings
OutFileName = "Project Invoice - " & InvoiceProjectNumber & " - " & InvoiceNumberText & ".pdf"
strFilter = ahtAddFilterItem(strFilter, "PDF Files (*.pdf)", "*.pdf")
OutFile = ahtCommonFileOpenSave(InitialDir:="", _
Filter:=strFilter, OpenFile:=False, FileName:=OutFileName, _
DialogTitle:="Save As", _
Flags:=ahtOFN_OVERWRITEPROMPT)
If blnInvoiceType = True Then
DoCmd.OutputTo acOutputReport, "rptProjectInvoicePDFVendorOrderVersion", acFormatPDF, OutFile, True
Else
DoCmd.OutputTo acOutputReport, "rptProjectInvoicePDFVendorNonOrderVersion", acFormatPDF, OutFile, True
End If
ShellExecuteA Application.hWndAccessApp, "open", OutFile, vbNullString, vbNullString, 1
Exit_cmdExportInvoiceToPDF_Click:
Exit Sub
Err_cmdExportInvoiceToPDF_Click:
If Err.Number = 2501 Then GoTo Exit_cmdExportInvoiceToPDF_Click
MsgBox Err.Number & " - " & Err.Description
Resume Exit_cmdExportInvoiceToPDF_Click
End Sub
Thanks
Jeff