Hi,
I hope someone can help, below is code that pdfs the current form and puts in this in an email using outlook to the users inputted into the code after clicking send on the form.
At present this leaves the PDF file in the directory the access file is located. Is there some code I could add at the end, so once sent it will delete the pdf file in that directory.
Function Palletemail()
Dim myOb As Object
Dim oMail As Object
Dim AutoSend As Boolean
Dim fileName As String, todayDate As String
Set myOb = CreateObject("Outlook.Application")
Set oMail = myOb.CreateItem(olMailItem)
'Export report in same folder as db with date stamp
todayDate = Format(Date, "DDMMYYYY")
fileName = Application.CurrentProject.Path & "\PalletIssue_" & todayDate & ".pdf"
DoCmd.OutputTo acForm, "frmPalletIssueFormWarehouse", acFormatPDF, fileName, False
'Set whether to send email automatically or make user press Send
AutoSend = True
With oMail
.Body = "Message"
.Subject = "PalletIssue"
.To = "user@email.com"
.CC = "user2@email.com"
.Attachments.Add fileName
If AutoSend Then
.Send
Else
.Display
End If
End With
Set oMail = Nothing
Set oApp = Nothing
End Function
I hope someone can help, below is code that pdfs the current form and puts in this in an email using outlook to the users inputted into the code after clicking send on the form.
At present this leaves the PDF file in the directory the access file is located. Is there some code I could add at the end, so once sent it will delete the pdf file in that directory.
Function Palletemail()
Dim myOb As Object
Dim oMail As Object
Dim AutoSend As Boolean
Dim fileName As String, todayDate As String
Set myOb = CreateObject("Outlook.Application")
Set oMail = myOb.CreateItem(olMailItem)
'Export report in same folder as db with date stamp
todayDate = Format(Date, "DDMMYYYY")
fileName = Application.CurrentProject.Path & "\PalletIssue_" & todayDate & ".pdf"
DoCmd.OutputTo acForm, "frmPalletIssueFormWarehouse", acFormatPDF, fileName, False
'Set whether to send email automatically or make user press Send
AutoSend = True
With oMail
.Body = "Message"
.Subject = "PalletIssue"
.To = "user@email.com"
.CC = "user2@email.com"
.Attachments.Add fileName
If AutoSend Then
.Send
Else
.Display
End If
End With
Set oMail = Nothing
Set oApp = Nothing
End Function