Good afternoon ALL,
I generate a PDF report on MS Access which I email to a recipient. The problem is that the name on the report and the data on the actual report differ. So, if I have the record for Jane Doe on the screen, Access generates and emails the data for John Doe. Below is the code I am using. What am I doing wrong? Please help!!
Code:
Dim oApp As New Outlook.Application
Dim Oemail As Outlook.MailItem
Dim FileName As String
Dim FilePath As String
Dim stLinkCriteria As String
stLinkCriteria = "[PAF_ID] = " & Me![PAF_ID]
FileName = Me.EE_LastName & "EEID " &Me!EEID & "JobID " & Me!PAF_JobID & "PAFID "& Me!PAF_ID
FilePath ="\\fps01\Output\" & FileName &".pdf"
DoCmd.OpenReport"rptPAF", acViewPreview, , stLinkCriteria, acHidden
DoCmd.OutputToacOutputReport, "rptPAF", acFormatPDF, FilePath
If oApp Is NothingThen
Set oApp = NewOutlook.Application
End If
Set Oemail =oApp.CreateItem(olMailItem)
With Oemail
.To ="reception@perfectbuilding.com"
.Subject ="PAF for: " & Me.EE_LastName & ", " &Me.EE_FirstName & "_EEID" & Me.EEID
.Attachments.Add FilePath
.Send
End With
Set Oemail =Nothing
Set oApp =Nothing
Kill FilePath