Results 1 to 8 of 8
  1. #1
    stu_C is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    38

    Auto Fill Outlook template via VBA

    Hi all
    I have a default Email template, I would like to create something in VBA that loads up the Email template, fills out the subject with data from the access form and also inputs data into a certain bookmark section is this possible?

    I have managed to get the template to open and input the subject automatically just struggling to get the bookmarks to work

    Set myOlApp = CreateObject("Outlook.Application")
    Set MyItem = myOlApp.CreateItemFromTemplate("C:\statusrep.oft")
    MyItem.Subject = "Status Report"
    MyItem.display

    I tried
    Set bm = oDoc.Bookmarks("BMCustomerName")
    bm.Range.Text = "TESTABC"
    oWd.Visible = True

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,923
    I have not used bookmarks.
    You could just use unique words as place sitters, then just use Replace() as I advised in another thread of your at another site?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    stu_C is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    38
    Quote Originally Posted by Welshgasman View Post
    I have not used bookmarks.
    You could just use unique words as place sitters, then just use Replace() as I advised in another thread of your at another site?
    how do i get it to check in the Email body

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,923
    Quote Originally Posted by stu_C View Post
    I am struggling to get Replace to work on a form let alone doing it on an Email body
    It is exactly the same I would have thought?, but that is because you have not looked to see how it works.

    I posted a link to the syntax and examples in the other thread.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    stu_C is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    38
    so In my Email Template body I put
    INVOICEREFNUMBERHERE

    when I do

    "INVOICEREFNUMBERHERE" = Replace("NVOICEREFNUMBERHERE", "me.INVOICEREFFIELD")

    vba doesn't like it

  6. #6
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,724

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,923
    Not suprised as it is gibberish.
    I have given you a link as to how Replace() is used, look at it.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    To use your example from post #5:

    Code:
    Dim sEmailBody as string
    
    sEmailBody="Dear ......" & vbcrlf & _
                       "Here is your Invoice INVOICEREFNUMBERHERE for the ......"
    sEmailBody=Replace(sEmailBody,"INVOICEREFNUMBERHERE",Me.INVOICEREFFIELD) 'replace placeholder with actual value from form
    sEmailBody=Replace(sEmailBody,"YourOtherPlaceholder",Me.OtherPlaceholderValue) '.....and so on
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Using Outlook Template
    By sovereign in forum Access
    Replies: 4
    Last Post: 12-06-2022, 10:20 AM
  2. Replies: 2
    Last Post: 06-15-2022, 12:09 PM
  3. Populate an Outlook e-mail template
    By jcc285 in forum Programming
    Replies: 1
    Last Post: 10-03-2019, 03:46 PM
  4. Replies: 2
    Last Post: 02-23-2012, 07:21 PM
  5. usings a outlook template
    By kylebmorris in forum Programming
    Replies: 0
    Last Post: 07-19-2010, 01:53 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