Hello and thank you for your time.
I am currently working on a loop that will either print out a letter if we do not have an email address on file for the individual or it emails the individual attaching the same report letter and, at this time, a .zip file with the 7 different files that need to go to tell the individual how to complete their training.
The code I have at this time is:
It does work but I need some help simplifying some things.
1. "Y:\" refers to a network drive that may or may no always be a "Y" but when I try to use the absolute path I get an error "Run-time error '-2147024894(80070002) Cannot find this file. Verify the path and file name are correct". :banghead:
2. Since most of the audience is not that good with computers it would be much better if I could attach the files individually without having a line of code for each file. This has its own issue in that if some of the users name on of the files wrong it will not send so it would be best if I could send all files in a specified folder, if that is not possible for some reason I will work around it.
I am currently working on a loop that will either print out a letter if we do not have an email address on file for the individual or it emails the individual attaching the same report letter and, at this time, a .zip file with the 7 different files that need to go to tell the individual how to complete their training.
The code I have at this time is:
Code:
Dim MyDb As DAO.Database
Dim oOutlook As Outlook.Application
Dim oEmail As Outlook.MailItem
Set oOutlook = Outlook.Application
Set oEmail = Outlook.CreateItem(olMailItem)
While Forms![Driver Training Due Letter]![ID] <> 0
DoCmd.OutputTo acOutputReport, "Driver Training Due Letter", acFormatPDF, "Y:\VTN - DAV\TrainingLetters\" & Forms![Driver Training Due Letter]![Full_Name] & ".pdf"
If Forms![Driver Training Due Letter]![E-mail Address] <> 0 Then
With oEmail
.To = Forms![Driver Training Due Letter]![E-mail Address]
.Subject = Forms![Driver Training Due Letter]!Subject
.Body = Forms![Driver Training Due Letter]!Body
.Attachments.Add "Y:\VTN - DAV\TrainingLetters\" & Forms![Driver Training Due Letter]![Full_Name] & ".pdf"
.Attachments.Add "Y:\VTN - DAV\TrainingPackage\Training Package.zip"
.Send
End With
Else
DoCmd.OpenReport "Driver Training Due Letter", acViewReport
DoCmd.SelectObject acReport, "Driver Training Due Letter"
DoCmd.PrintOut , , , acLow, 1
DoCmd.Close acReport, "Driver Training Due Letter", acSaveNo
End If
DoCmd.GoToRecord acForm, "Driver Training Due Letter", acNext
Wend
End Sub
It does work but I need some help simplifying some things.
1. "Y:\" refers to a network drive that may or may no always be a "Y" but when I try to use the absolute path I get an error "Run-time error '-2147024894(80070002) Cannot find this file. Verify the path and file name are correct". :banghead:
2. Since most of the audience is not that good with computers it would be much better if I could attach the files individually without having a line of code for each file. This has its own issue in that if some of the users name on of the files wrong it will not send so it would be best if I could send all files in a specified folder, if that is not possible for some reason I will work around it.
Last edited: