Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Join Date
    Jan 2007
    Posts
    23

    Unanswered: create email from access

    I would like to create an email message from Access based on a query. Query provides the email address. I would like the email address to be added to the 'to' line in the Outlook email message. Any help is appreciated!

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    You can use SendObject in VBA, either using a recordset or DLookup to get the address (or anything else) from the query.
    Paul

  3. #3
    Join Date
    Jan 2007
    Posts
    23

    example?

    Thanks, but could you provide an example? Thanks!

  4. #4
    Join Date
    Jan 2007
    Location
    California, USA
    Posts
    520
    Type SendObject in the Immediate window, place the cursor on SendObject, and press F1. Microsoft explans the command and gives an example too. Please note, the first 4 parameters for the SendObject command, that describe the object to send, are OPTIONAL. Therefore, you don't need to send an object, but you can use this command to send a simple e-mail message which is what it sounds like you want.
    After using Access help, if you still have questions, please ask.

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Macros are not the nicest way of doing anything, but it might be worth taking a look at making on to do this - because it's the simplest starting point.

    Remember that if you right click and "Save as..." on a macro you can save it as a module (which will give you a kick start with the sytax etc)
    George
    Home | Blog

  6. #6
    Join Date
    Sep 2006
    Posts
    265
    Macros are not particularly liked by 2003 - Modules are preferred. Converting Macros to Modules is a good habit to get into. They are also reusable and saves additional coding particularly when using "With CodeContextObject", this also can be used instead of Event Procedures on forms or reports.

    A nice program is pdf995 which converts objects into pdfs which is handy if not all your audience has Access.

  7. #7
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Best thing about converting macros to modules:

    Error handling!
    George
    Home | Blog

  8. #8
    Join Date
    Jan 2007
    Posts
    23

    To Vic

    Yes, I do not need to send an object but rather need to create an email with the email address in the To line. The user obtains the email address via a form. They enter a matter number that identifies the party for whom they would like to see the email. Once they have the correct email they should click a button that then creates the email with the email address in the To line.

    GolferGuy
    Registered User Join Date: Jan 2007
    Location: California, USA
    Posts: 107

    Type SendObject in the Immediate window, place the cursor on SendObject, and press F1. Microsoft explans the command and gives an example too. Please note, the first 4 parameters for the SendObject command, that describe the object to send, are OPTIONAL. Therefore, you don't need to send an object, but you can use this command to send a simple e-mail message which is what it sounds like you want.
    After using Access help, if you still have questions, please ask.
    __________________
    Vic
    http://www.vicrauch.com

  9. #9
    Join Date
    Jan 2007
    Location
    California, USA
    Posts
    520
    Have you looked at the help file for SendObject? Please look at that, and then any questions you have to help make that clear, please ask. I think that once you see what SendObject will do, you will see that filling in the To line is just part of using that command, SendObject.

  10. #10
    Join Date
    Jan 2007
    Posts
    23
    I did read it and it was very helpful. I understand the basics of it and how it creates a basic email with attachment, however I'm not understanding what the syntax should look like for the sendObject command when the email is obtained through a query and then that email is used to put in the To line.

    Thanks!

  11. #11
    Join Date
    Sep 2006
    Posts
    265
    There are issues here one the email address and two the object to be sent. I use CDONTS driven by a form and get the user to "collect" the object. Try forgive me if the quotes aren't quite right!

    Function SendDBObject()


    With CodeContextObject

    DoCmd.SendObject acSendReport, "MyReport", acFormatXLS, _
    & "' .[EmailAddress] & "',"MyReport", , False

    End With

    End Function

    The With CodeContextObject refers to the Form and the .[EmailAddress] refers to the forms email address control.

  12. #12
    Join Date
    Jan 2007
    Posts
    23
    I am not looking to send an object. I have a form that has a button, when clicked it invokes a query. The user enters the parameter value and the results produce the record that contains, amongst other info, an email. This is the email that needs to be used to produce the email (and put in the To line).

    Thanks.

  13. #13
    Join Date
    Sep 2006
    Posts
    265
    Was is the parameter value that qualifies the Query. If one assumes that there is a relationship between Parameter Value and the Client you should be able to get the Email address from a Combobox. On the ComboBox if there is a column for "Yor Parameter", Client, and EmailAddress on AfterUpdate

    With CodeContextObject

    .[EmailAddress] = .[MyParameterBox].Column(2)

    End with


    i.e. The Email Address needs to be on your form.

    Simon

  14. #14
    Join Date
    Jan 2007
    Location
    California, USA
    Posts
    520
    As I understand what you are wanting is to get the email from the query, which is fine, but I don't understand if you are calling the message you will be sending the email, or if you are calling the To Address the email. For this purpose, I will assume you are getting both from the query.
    You need to make a recordset out of the query, I will assume you know how.
    Then, when looping through the records of the query, and I will use "QryRS" for Query recordset.
    Code:
    docmd.SendObject ,,,QryRS.emailAddress,,,"This is the Subject",QryRS.emailMessage
    HTH,

  15. #15
    Join Date
    Jan 2007
    Posts
    23

    to Vic

    This example helps a lot, thanks. Yes, I'm only wanting to obtain the email address from the query and that have that added to the To line in the email. I do not want to add an attachment, nor a subject line.

    Could you give an example of looping through a recordset? also, why would I have to loop through the recordset if the user selects a particular record via the parameter they enter for the query (query will provide one record as a result).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •