How to send email to predetermined address in Access?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yeske03
    New Member
    • Feb 2009
    • 9

    #1

    How to send email to predetermined address in Access?

    I've created a form for use by our employees. I have it simple as possible with a New Record, Save Record, and Email command buttons.

    The email command is set up to mail a specific query that I have created. Everything works properly, but when you click to email a command pops up to select my format, and then opens microsoft office to have me type in the email addresses.

    Code:
    Private Sub MAIL_Click()
    On Error GoTo Err_MAIL_Click
    
        Dim stDocName As String
    
        stDocName = "PURCHASE ORDER Query"
        DoCmd.SendObject acReport, stDocName
    
    Exit_MAIL_Click:
        Exit Sub
    
    Err_MAIL_Click:
        MsgBox Err.Description
        Resume Exit_MAIL_Click
        
    End Sub

    That is the default code for email. What needs to be done so that when I click the email command it selects the format and sends to predetermined addresses automatically?

    I am an Access novice, so any help would be greatly appreciated.
    Last edited by Niheel; Jan 26 '11, 08:05 PM.
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Use the Full Syntax of SendObject(), while stating the Output Format, as in either one of the five examples below:
    Code:
    DoCmd.SendObject acSendReport, stDocName, acFormatDAP, "<Some E-Mail Address>", , , "<Subject of E-Mail>", "<E-Mail Message>", False
    DoCmd.SendObject acSendReport, stDocName, acFormatHTML, "<Some E-Mail Address>", , , "<Subject of E-Mail>", "<E-Mail Message>", False
    DoCmd.SendObject acSendReport, stDocName, acFormatRTF, "<Some E-Mail Address>", , , "<Subject of E-Mail>", "<E-Mail Message>", False
    DoCmd.SendObject acSendReport, stDocName, acFormatTXT, "<Some E-Mail Address>", , , "<Subject of E-Mail>", "<E-Mail Message>", False
    DoCmd.SendObject acSendReport, stDocName, acFormatXLS, "<Some E-Mail Address>", , , "<Subject of E-Mail>", "<E-Mail Message>", False

    Comment

    • yeske03
      New Member
      • Feb 2009
      • 9

      #3
      Thanks, that works great now. Is there a way I can add that code to the command button I have to close the application, so that it will email the file and close when finished?

      Comment

      • yeske03
        New Member
        • Feb 2009
        • 9

        #4
        Nevermind on the last post. I moved my DoCmd.Quit up a few lines and works perfectly now. Thanks for the help ADezzi.

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          If you wish to add the Code when you Close the Application, you should probably place it in the Close() Event of your Main Form:
          Code:
          Private Sub Form_Close()
            DoCmd.SendObject acSendReport, stDocName, "<Format>", "<Some E-Mail Address>", , , "<Subject of E-Mail>", "<E-Mail Message>", False
          End Sub

          Comment

          Working...