Send an e-mail with an attachment using Access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • newuser1980
    New Member
    • Mar 2007
    • 1

    Send an e-mail with an attachment using Access

    Hey,

    I am in the process of writing some VBA code that will do the following:

    1) Create and send an e-mail using Outlook with an excel file attached. The excel files are present in a specified folder.

    Any help to accomplish this will be highly appreciated.

    Thanks.
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    Originally posted by newuser1980
    Hey,

    I am in the process of writing some VBA code that will do the following:

    1) Create and send an e-mail using Outlook with an excel file attached. The excel files are present in a specified folder.

    Any help to accomplish this will be highly appreciated.

    Thanks.
    Excel has a sendMail command
    Code:
    	Set wb = ActiveWorkbook
    	With wb
    		.SendMail "email address", _
    			"Subject line"
    		.Close False
    	End With
    You would have to nest this into a loop to run through and open each of the excel files.

    Mary

    Comment

    • mattkorguk
      New Member
      • Mar 2007
      • 28

      #3
      Hi,
      I've always used this:
      Code:
       On Error GoTo cmdEmail_Err
          DoCmd.SendObject acSendQuery, "qryName", acFormatXLS, "", "", "", " See attachment", "", True, ""
      cmdEmail_Exit:
          Exit Sub
      
      cmdEmail_Err:
          MsgBox "You cancelled and did not send the email", vbExclamation
          Resume cmdEmail_Exit
          
          DoCmd.SetWarnings True
          Me.Refresh
      Hope that helps.
      Matt

      Comment

      Working...