Cannot Find PDF File (1 Viewer)

mike60smart

Registered User.
Local time
Today, 11:14
Joined
Aug 6, 2017
Messages
1,905
Hi Everyone

Vlad gave me what I thought was a solution in the following Link, however I now find I am getting the following error.
Link
The Code I am using is as follows.

Any help appreciated.

Code:
Private Sub cmdPreview_Click()

10        On Error GoTo cmdPreview_Click_Error
20        If Me.CarrierPaid = -1 Then

30            If Me.Dirty Then Me.Dirty = False
40            MsgBox "A Copy of the PDF will be saved to the C Drive EMails Folder", vbInformation
              Dim strSQL As String
              Dim outApp As Object
              Dim outMail As Object
              Dim strReportname As String
              Dim strMailItem As String
              Dim strWhere As String
              Dim strToWhom As String
              Dim strMsg As String
              Dim strSubject As String
              Dim strPath As String

50            strToWhom = Me.CarriereMail
60            strWhere = "[CarrierID]=" & Me.CarrierID
70            strSubject = "Carrier Settlement"
80            strReportname = "CarrierSettlement"

90            strMsg = "Find attached latest Settlement Details"
100           If Dir("C:\Emails", vbDirectory) = "" Then MkDir "C:\Emails"

110           strPath = "C:\Emails\" & Format(Date, "mmddyyyy") & "- Carrier Settlement" & [LoadNumber] & ".pdf"
     
120           Set outApp = CreateObject("Outlook.Application")
130           Set outMail = outApp.CreateItem(0)

140           DoCmd.OpenReport "CarrierSettlement", acViewPreview

150       End If
160       With outMail
170           .To = strToWhom
180           .Subject = strSubject
190           .Attachments.Add strPath
200           .Body = strMsg
210           .Display
220       End With
         
230       On Error GoTo 0
240       Exit Sub

cmdPreview_Click_Error:

250       MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdPreview_Click, line " & Erl & "."

End Sub
 

Attachments

  • Error.png
    Error.png
    8.3 KB · Views: 57
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 05:14
Joined
Feb 28, 2001
Messages
27,186
So my first question is, what is in strPath (which is on line 190)? I would put a breakpoint on that line and examine strPath for the failing case in question. Either hover the mouse over strPath in that line OR open the Immediate window and do a DEBUG.PRINT strPath to verify that its contents are exactly what you expected them to be.

Second question, assuming that strPath appears to make sense, is ... can you find that path using Windows explorer?
 

mike60smart

Registered User.
Local time
Today, 11:14
Joined
Aug 6, 2017
Messages
1,905
Hi Doc Man

I am puzzled because the following Code generated the following yesterday:-
Code:
Private Sub cmdPreview_Click()

10        On Error GoTo cmdPreview_Click_Error
20        If Me.CarrierPaid = -1 Then

30            If Me.Dirty Then Me.Dirty = False
40            MsgBox "A Copy of the PDF will be saved to the C Drive EMails Folder", vbInformation
              Dim strSQL As String
              Dim outApp As Object
              Dim outMail As Object
              Dim strReportname As String
              Dim strMailItem As String
              Dim strWhere As String
              Dim strToWhom As String
              Dim strMsg As String
              Dim strSubject As String
              Dim strPath As String

50            strToWhom = Me.CarriereMail
60            strWhere = "[CarrierID]=" & Me.CarrierID
70            strSubject = "Carrier Settlement"
80            strReportname = "CarrierSettlement"

90            strMsg = "Find attached latest Settlement Details"
100           If Dir("C:\Emails", vbDirectory) = "" Then MkDir "C:\Emails"

110           strPath = "C:\Emails\" & Format(Date, "mmddyyyy") & "- Carrier Settlement" & [LoadNumber] & ".pdf"
              Debug.Print strPath
120           Set outApp = CreateObject("Outlook.Application")
130           Set outMail = outApp.CreateItem(0)

140           DoCmd.OpenReport "CarrierSettlement", acViewPreview
145           DoCmd.OutputTo acOutputReport, "CarrierSettlement", acFormatPDF, "C:\Emails\" & Format(Date, "mmddyyyy") & "- CarrierSettlement" & [LoadNumber] & ".pdf", True

150       End If
160       With outMail
170           .To = strToWhom
180           .Subject = strSubject
190           .Attachments.Add strPath
200           .Body = strMsg
210           .Display
220       End With
          
230       On Error GoTo 0
240       Exit Sub

cmdPreview_Click_Error:

250       MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdPreview_Click, line " & Erl & "."

End Sub
1. Produced a PDF Report in Microsoft Edge
2. Produced the Report in Print Preview
3. Opened an EMail message with the PDF as an attachment.

Today all it is doing is :-
1. Produces a PDF Report in Microsoft Edge
2. Produces the Report in Print Preview
3. Displays the error regarding unable to find File and does not generate the email.

Did a DEBUG>Print strPath and it produces the following:-


C:\Emails\03182023- Carrier Settlement133875.pdf
 

mike60smart

Registered User.
Local time
Today, 11:14
Joined
Aug 6, 2017
Messages
1,905
Hi Doc Man

Well it looks like it was all down to a missed Hyphen in the Path

160 strPath = "C:\Emails\" & Format(Date, "mmddyyyy") & "- AgentSettlement -" & [LoadNumber] & ".pdf"

200 DoCmd.OutputTo acOutputReport, "AgentSettlement", acFormatPDF, "C:\Emails\" & Format(Date, "mmddyyyy") & "- AgentSettlement -" & [LoadNumber] & ".pdf", True

I had missed one of the Hyphens in the strPath

The above has now resolved this issue.

Many thanks for looking
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 05:14
Joined
Feb 28, 2001
Messages
27,186
No problem. At least you had something to look at and compare against reality.
 

Users who are viewing this thread

Top Bottom