Results 1 to 6 of 6
  1. #1
    avarusbrightfyre is offline Advanced Beginner
    Windows Vista Access 2003
    Join Date
    Sep 2009
    Posts
    60

    Command button to open email template

    So I have a command button that I'd really like to be able to use to create an email message in outlook that pulls from a specific template and fills in the record information from the currently selected record.



    I've looked around and the docmd.sendobject seems to be the closest thing, but it seems to attach the template rather than putting the text into the body of the paragraph. I am aware that you can put text in the docmd.sendobject function arguments, but I want the end user to be able to adjust what the message says without having to know access code and such.

    Is there a way to use the send object function to pull from a specified template and place that text into the body of the message? Or is there a better way other than send object to do what I'm looking for?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Here's how I send an email:
    Code:
    'open Outlook, attach zip folder or file, send e-mail
    Dim appOutLook As Outlook.Application
    Dim MailOutLook As Outlook.MailItem
    Set appOutLook = CreateObject("Outlook.Application")
    Set MailOutLook = appOutLook.CreateItem(olMailItem)
    With MailOutLook
        .BodyFormat = olFormatRichText
        .To = "email address"
        ''.cc = ""
        ''.bcc = ""
        .Subject = "text here"
        .HTMLBody = "text here"
        .Attachments.add ("path\filename")
        ''.DeleteAfterSubmit = True 'This would let Outlook send the note without storing it in your sent bin
        .send
    End With
    You can get the info for the email elements from textboxes on a form or recordset.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    avarusbrightfyre is offline Advanced Beginner
    Windows Vista Access 2003
    Join Date
    Sep 2009
    Posts
    60
    I'm not sure if I'm reading the code right. It seems to me that this code will generate an email with whatever you put in each line and can't be changed by a person who doesn't know the code. Also, I'd like the body of the text to come from a pre-made template that the user can open and edit without the need to understand access code. I don't really need any attachments.

    What I'm looking for is an option that will pull the body of the email message from a template word document that is attached to the database and will then pull the required information from the currently selected specific record in access and "fill in the blanks" like the regular mail merge does.

    I'm already able to do this with word documents using a free code set I found online (was a huge blessing!) that automatically opens the specified template and points to the record I have open in access and then automatically merges the document, but I have no idea how it works. I'm looking for exactly the same thing, but for an email instead.

    So....is there a way to pull up an outlook message that draws the body of the email from an already created word document? I would preferably like it to just create the message and wait for the user to click the "send" button. Also, I need the end user to be able to adjust the template if needed when I'm gone and they're not going to be able to go in and change the VBA code.

    All that being said, I'm not looking for a free handout or anything, just point me in the right direction. I can do research if someone knows a function that has all the things I need for it.

    Thanks again!

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Any of the items you see in quotes (such as "email address") can be replaced with a variable. How you get that variable populated is the trick. I have never tried to grab content from a Word document and feed it into code. It's been a looooong time since I've done a document merge and was accomplished entirely within a word processor program, no database. Documents merged because of embedded code tags in both documents (an address list and a letter). You have a Word document template as an attachment in a record? This template must have embedded relationships to fields of a form.

    So modify the code I provided to refer to a form as source of email elements, like:
    .To = Me!fieldname
    .HTMLBody = Me!fieldname

    Replace .Send with .Display and the message will open and wait.
    Comment out or delete the line about attachments.

    Put code behind that form in a button Click event.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    avarusbrightfyre is offline Advanced Beginner
    Windows Vista Access 2003
    Join Date
    Sep 2009
    Posts
    60
    I definitely understand what you mean about pulling from fields on a form, but I really need to be able to pull from an external document. None of the other people in my office have any access development experience and they need to be able to just open up the required template, change it to what they want it to read and then save it and the access program will just pull the required text and merge fields from the word document. Otherwise, my master plan here won't work out, lol.

    Is there a way to set the body of the email to pull from a word document? I understand all the other entries, it's the extracting from the word document that I don't know anything about.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    What you need to do is have user edit the Word document content in a form. Then have the Word document grab the info from the form (or actually the record that the form is entering data into). This is a merge procedure. Check this article http://office.microsoft.com/en-us/ac...010285219.aspx

    Then the email procedure can refer to the same form. I don't know any way for the email procedure to grab data from a Word document.

    I don't know if the edits can be done directly in the Word template and then those edits fed into Access. Might be doable with VBA coding in Word. I have never programmed in Word. Maybe the email procedure can be in a module in Word. Don't know.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 10-01-2010, 11:12 PM
  2. Use a command button to open a form
    By johnpaul in forum Forms
    Replies: 24
    Last Post: 09-23-2010, 12:29 PM
  3. Replies: 1
    Last Post: 07-27-2010, 02:27 PM
  4. Replies: 1
    Last Post: 07-07-2010, 11:06 AM
  5. Open a linked subform with a command button
    By flablueeyedblond in forum Forms
    Replies: 0
    Last Post: 11-18-2005, 01:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums