Private Sub cmdShip_Click()
On Error GoTo Err_cmdShip_Click
Dim stRptName As String, stParam As String, stLinkCriteria As String, stDBpath As String, stFTPpath As String
Dim iPreview As Integer, iDialog As Integer, blnPrintIt As Boolean
stDBpath = CurrentProject.Path & "\"
stFTPpath = stDBpath & "Gazette\"
iPreview = acViewPreview
If Me.ChkPreview Then
' iPreview = 2
iDialog = acWindowNormal
Else
iDialog = acHidden
End If
stRptName = "Main_by_Ship"
stParam = Replace(LCase(Me.cboShip.Value), " ", "_")
stLinkCriteria = "[Ship] = '" & Me.cboShip.Value & "'"
'DoCmd.CopyObject , stParam, acReport, stRptName
If Me.ChkPreview Then
DoCmd.OpenReport stRptName, iPreview, , stLinkCriteria, iDialog
Else
DoCmd.OpenReport stRptName, iPreview, , stLinkCriteria, iDialog
DoCmd.OutputTo acOutputReport, stRptName, acFormatPDF, stFTPpath & stParam & ".pdf", False
DoCmd.Close acReport, stRptName
End If
'DoCmd.DeleteObject acReport, stParam
Exit_cmdShip_Click:
Exit Sub
Err_cmdShip_Click:
MsgBox Err.Description
Resume Exit_cmdShip_Click
End Sub
Private Sub cmdDeliveryNote_Click()use vba to change the name of the pdf either when it is created or after (use the name function)
I use outlook automation to creat the email and the pdf
Away from my computer at the moment and that does all that so share your vba code for creating the pdf and I can provide a more focused response
Private Sub cmdPDF_Click()
On Error GoTo Err_Handler
Const FOLDER_EXISTS = 75
Const MESSAGE_TEXT1 = "No current invoice."
Const MESSAGE_TEXT2 = "No folder set for storing PDF files."
Dim strFullPath As String
Dim varFolder As Variant
' Ensure current record is saved
If Me.Dirty Then Me.Dirty = False
If Not IsNull(Me.InvoiceNumber) Then
' build path to save PDF file
varFolder = DLookup("Folderpath", "pdfFolder")
If IsNull(varFolder) Then
MsgBox MESSAGE_TEXT2, vbExclamation, "Invalid Operation"
Else
' create folder if does not exist
varFolder = varFolder & "\" & Me.Customer.Column(1)
MkDir varFolder
strFullPath = varFolder & "\" & Me.Customer.Column(1) & " " & Me.InvoiceNumber & ".pdf"
DoCmd.OutputTo acOutputReport, "rptInvoice", acFormatPDF, strFullPath, True
End If
Else
MsgBox MESSAGE_TEXT1, vbExclamation, "Invalid Operation"
End If
Exit_Here:
Exit Sub
Err_Handler:
Select Case Err.Number
Case FOLDER_EXISTS
Resume Next
Case Else
MsgBox Err.Description
Resume Exit_Here
End Select
End Sub
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Const DUPLICATE_KEY = 3399
Const MESSAGE_TEXT = "The invoice number has been amended due to " & _
"another user having created an invoice with the same number before you " & _
"attempted to save this invoice record."
Select Case DataErr
Case 0
'no error
Case DUPLICATE_KEY
' anticipated error
Me.InvoiceNumber = CStr(Val(DMax("InvoiceNumber", "Invoices")) + 1)
Response = acDataErrContinue
MsgBox MESSAGE_TEXT, vbInformation, "Warning"
Case Else
'unknown Error
MsgBox Err.Description, vbExclamation, "Error"
End Select
End Sub
Here is some code from my first Access database.
This produces a report for the selected ship.
Code:Private Sub cmdShip_Click() On Error GoTo Err_cmdShip_Click Dim stRptName As String, stParam As String, stLinkCriteria As String, stDBpath As String, stFTPpath As String Dim iPreview As Integer, iDialog As Integer, blnPrintIt As Boolean stDBpath = CurrentProject.Path & "\" stFTPpath = stDBpath & "Gazette\" iPreview = acViewPreview If Me.ChkPreview Then ' iPreview = 2 iDialog = acWindowNormal Else iDialog = acHidden End If stRptName = "Main_by_Ship" stParam = Replace(LCase(Me.cboShip.Value), " ", "_") stLinkCriteria = "[Ship] = '" & Me.cboShip.Value & "'" 'DoCmd.CopyObject , stParam, acReport, stRptName If Me.ChkPreview Then DoCmd.OpenReport stRptName, iPreview, , stLinkCriteria, iDialog Else DoCmd.OpenReport stRptName, iPreview, , stLinkCriteria, iDialog DoCmd.OutputTo acOutputReport, stRptName, acFormatPDF, stFTPpath & stParam & ".pdf", False DoCmd.Close acReport, stRptName End If 'DoCmd.DeleteObject acReport, stParam Exit_cmdShip_Click: Exit Sub Err_cmdShip_Click: MsgBox Err.Description Resume Exit_cmdShip_Click End Sub
strFullPath = varFolder & "\" & Me.Customer.Column(1) & " " & Me.InvoiceNumber & ".pdf"
DoCmd.OutputTo acOutputReport, "rptInvoice", acFormatPDF, strFullPath, True
Dim strTo As String
Dim strSubject As String
Dim strMessageText As String
Me.Dirty = False
strTo = Me.Email
strSubject = "Invoice Number " & Me.InvoiceNumber
strMessageText = Me.Customer.Column(1) & ":" & _
vbNewLine & vbNewLine & _
"Your latest invoice is attached." & _
vbNewLine & vbNewLine & _
"Customer Accounts Department, Widget Supply Company"
DoCmd.SendObject ObjectType:=acSendReport, _
ObjectName:="rptInvoice", _
OutputFormat:=acFormatPDF, _
To:=strTo, _
Subject:=strSubject, _
MESSAGETEXT:=strMessageText, _
EditMessage:=True
WHERE Invoices.InvoiceNumber = [Forms]![frmInvoice]![InvoiceNumber];