Runtime error when trying to attach a file to email

gmatriix

Registered User.
Local time
Today, 06:51
Joined
Mar 19, 2007
Messages
365
Hello All,

I am trying to attach a excel file to email. I have the file being exported to a location then I would like for the email to attach but I keep getting runtime saying that it has been moved or deleted....and the file is there...

Do I need to put a pause in or something to give time to save?

Any Ideas?

Code:
DoCmd.SetWarnings False

Dim FilNam As String
Dim Seeit As String
Dim iTemp As Integer

FilNam = "\\blah blah blah"

DoCmd.OpenQuery "la la report", acViewNormal, acEdit
DoCmd.OutputTo acOutputTable, "la la report", "Excel97-Excel2003Workbook(*.xls)", FilNam, False, "", , acExportQualityPrint

'Ignore errors to allow for error evaluation
    On Error Resume Next
    iTemp = GetAttr(FilNam)
    
'Check if error exists and set response appropriately
    Select Case Err.Number
    Case Is = 0
        FileOrDirExists = True
    Case Else
        FileOrDirExists = False
    End Select
    
     'Resume error checking
    On Error GoTo 0
    

    
If FileOrDirExists Then

Dim outl As Outlook.Application
Set outl = New Outlook.Application
Dim mi As Outlook.MailItem
Set mi = outl.CreateItem(olMailItem)
mi.HTMLBody = "<p>Hello,</p>" & "<p>Give me some chicken"
mi.Subject = "Ribs and Chicken report"
mi.To = "greezychick@blast.com"
mi.Send
mi.Attachments.Add ("The location where the file is at...lol")
Set mi = Nothing
Set outl = Nothing
Application.Quit
Else

Dim outll As Outlook.Application
Set outll = New Outlook.Application
Dim mi1 As Outlook.MailItem
Set mi1 = outl.CreateItem(olMailItem)
mi1.HTMLBody = "Hello"
mi1.Subject = "Tabot sauce"
mi1.To = "greezychick@blast.com"
mi1.Send
Set mi1 = Nothing
Set outll = Nothing
Application.Quit
End If


Proc_702_Auto_Qry_Err:
    MsgBox Error$
 
1. use something like Dir() or Scripting.Filesystemobject.FileExists() to check if a file exists. Don't hackaround with GetAttr and On Error stuff.

2. Try changing this line:
mi.Attachments.Add ("The location where the file is at...lol")
to
mi.Attachments.Add Filnam
 
You are not using this as a function (i.e. x = mi.attachments.add). You also are not using it as an explicit CALL,

I believe you need to omit the parentheses in this case. Sometimes parentheses force an oddball evaluation of the argument.

Code:
mi.Attachments.Add "The location where the file is at...lol"

EDIT: I see Isaac and I caught the same thing.
 
1. use something like Dir() or Scripting.Filesystemobject.FileExists() to check if a file exists. Don't hackaround with GetAttr and On Error stuff.

2. Try changing this line:
mi.Attachments.Add ("The location where the file is at...lol")
to
mi.Attachments.Add Filnam
Thank you I have removed the ( ) and I get the same thing....do I need to refresh something...folder maybe?
 
Please post your full, current code.
 

Users who are viewing this thread

Back
Top Bottom