Vb E-mail

I have a the following code, Im trying to attach a query-report in the attachment but it gives a --Cant find this file and file name make sure the path and file name are correct.
Can someone please help.

Dim objOutlook As Outlook.Application
Dim objMailItem As Outlook.MailItem
Dim objAttachment As Outlook.Attachment

Set objOutlook = New Outlook.Application
Set objMailItem = objOutlook.CreateItem(olMailItem)
Set objattachments = objMailItem.Attachments

   DoEvents
   With objMailItem

    .To = Me.Vendoremail
    .Subject = "Festiva Resorts Purchase Order"
    .Body = "Dear " & Me.Vendor_Name & "," & vbCrLf _
      & "Attachted above is a Purchase Order." & vbCrLf & vbCrLf _
      & "Festiva Resorts"
     .Attachments.Add ("E-mail_Purchase_Order")
     .Importance = olImportanceHigh

.Send

   End With
   DoEvents
       
Exit_Command80_Click:
    Exit Sub

Err_Command80_Click:
    MsgBox Err.Description
    Resume Exit_Command80_Click
   
End Sub


Thanks for your time.
fsueduAsked:
Who is Participating?
 
leeskelton83Connect With a Mentor Commented:
You can't attach a report or query .You have to create an Excel file or some other type of file first and then attach it.

  .To = Me.Vendoremail
    .Subject = "Festiva Resorts Purchase Order"
    .Body = "Dear " & Me.Vendor_Name & "," & vbCrLf _
      & "Attachted above is a Purchase Order." & vbCrLf & vbCrLf _
      & "Festiva Resorts"
     DoCmd.OutputTo acOutputQuery, "yourQuery", acFormatXLS, "c:\YourPath.xls" '----Export Here
     .Attachments.Add ("c:\YourPath.xls")
     .Importance = olImportanceHigh


0
 
RDWaibelCommented:
save the fact that you can export a query or report in the MS Snapshot format.  This is fine IF your user/receipiant has the viewer.

Excel or RTF (rich text format) are normally prefered.
0
 
rockiroadsCommented:
without having to use outlook automation, u could just use this



docmd.SendObject acSendQuery,"queryname",acFormatXLS,Me.Vendoremail,, "Festiva Resorts Purchase Order",Dear " & Me.Vendor_Name & "," & vbCrLf & "Attachted above is a Purchase Order." & vbCrLf & vbCrLf & "Festiva Resorts"
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
leeskelton83Commented:
save the fact that you can export a query or report in the MS Snapshot format.  This is fine IF your user/receipiant has the viewer.

Even then you would have to export the file first, wouldn't you?
0
 
RDWaibelCommented:
Yes, but based on the layout of the report/query, you have a nicer looking attachment.
0
 
shanesuebsahakarnCommented:
While you could use SendObject, it has many limitations and a number of known bugs (as well as not working with several common e-mail clients). Exporting and attaching is a better option, especially since this allows you to add multiple attachments per e-mail. This may be of use:

http://www.granite.ab.ca/access/email.htm
0
All Courses

From novice to tech pro — start learning today.