Solved Run Time Error - Cannot find file - Attaching to email (1 Viewer)

allen675

Member
Local time
Today, 10:06
Joined
Jul 13, 2022
Messages
124
Hi again!

Really not sure why I'm getting this message. I have various pieces of VBA code all pointing to this same document in my DB with no problems. Now I want to try and attach this file to an email I'm getting this error message. The file exists, the path hasn't changed!

This is the code:

Code:
Private Sub Command23_Click()
Dim oApp As New Outlook.Application
Dim oEmail As Outlook.MailItem
Dim fileName As String

'Preparing Spreadsheet to send to directors
'First select the tracker just created
fileName = Application.CurrentProject.Path & "\Tracker"

'Email result of spreadsheet just created
Set oEmail = oApp.CreateItem(olMailItem)
With oEmail
    .Recipients.Add "test@test.com"
    .Subject = "Tracker"
    .Body = "Please find attached this weeks Tracker"
    .Attachments.Add fileName
    .Display
End With

End Sub

Help most appreciated
 

Attachments

  • Error.PNG
    Error.PNG
    7.4 KB · Views: 89

allen675

Member
Local time
Today, 10:06
Joined
Jul 13, 2022
Messages
124
The file
 

allen675

Member
Local time
Today, 10:06
Joined
Jul 13, 2022
Messages
124
I know what your going to say, no extension!
Just added extension to code and it works!

Question then, elsewhere in my VBA code I have this file referenced but without the extension, why did it cause a problem here?
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:06
Joined
Sep 21, 2011
Messages
14,050
Just added extension to code and it works!

Question then, elsewhere in my VBA code I have this file referenced but without the extension, why did it cause a problem here?
I would sincerely doubt that, but you would have to show us the code to prove it. :)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:06
Joined
May 7, 2009
Messages
19,175
Question then, elsewhere in my VBA code I have this file referenced but without the extension, why did it cause a problem here?
maybe it thinks that it is a folder.
a dot (.) as suffix can do?
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:06
Joined
Sep 21, 2011
Messages
14,050
Yep you are correct, my other code does include the file extension! Doh! 👍
Computers do not just change their mind (well except for Google minis', they have a mind of their own :( )
So unless something changes, it will produce the same result.
 

Users who are viewing this thread

Top Bottom