Results 1 to 5 of 5
  1. #1
    BaaBaaBristol is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2021
    Posts
    11

    VBA code for email template

    Good evening,

    I have embedded some code in a form on my Access database that automatically opens and generates basic content for an email. I want to use these as pre-defined emails for specific situations, but I can't work out how to add paragraphs, only to have one long paragraph without breaks.

    The code is here:

    Private Sub Command17_Click()
    DoCmd.SendObject acSendNoObject, , , "works4youth@southglos.gov.uk", , Me.Text13.Value, "Insert Subject", "Edit body of email message. How do I start a new paragraph? Like this? Or this?", True
    End Sub


    Command17 is currently the button I am testing. The part of the code that begins "Edit body of email message......" is the body where I want to be able to add paragraph breaks. Please could you advise? I am not an advanced user and don't want to make it too complicated!

    Is there anything that can be added/amended in the code I am using to ATTACH a letter, if that is easier than trying to format the text using VBA? I could have a word document outlining what I am trying to say and simply shorten the body of the email here.

    Many thanks,

    B

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Unfortunately I think you will consider this complicated. You build the body text in code and use html tags <P> or <BR> to get the breaks you want, but the email has to be rich text or html format as far as I know. Don't think it would work with plain text emails but I've never tried. However, I'm not sure you can do this with SendObject method but someone else will likely confirm or refute that. Your thread is a bit confusing on that because you're using acSendNoObject yet perhaps want to include an attachment. AFAIK, you have to create a procedure that will allow you to create all the variables (Subject, Body,etc.) while working with Outlook if you want to send attachments. You could probably find lots of code examples to help you with this. You probably should confirm what email client you'd be using as well, as that can matter a lot.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    Try adding some carriage returns?

    "Edit body of email message. How do I start a new paragraph? " & vbcrlf & "Like this? " & vbcrlf & vbcrlf & "Or this?"

    This will only work I suspect if you aren't using HTML format.
    The other option is to use Outlook automation which allows you to specify HTML as a format and then you be really creative with tags etc. to make a very pretty email if required.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #4
    BaaBaaBristol is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2021
    Posts
    11
    Thanks for your quick reply. I am using Outlook 365 as the email client. If it is as simple as acSendObject and being able to name an attachment, then that would probably be okay for now.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    You can't send a file like a Word document with SendObject. That only sends database objects. There are a gazillion web posts for code that will work with Outlook to send files. You could research and try if you want to learn a bit but I bet if you wait, someone here will "give you a fish".
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Generating email with template
    By MTSPEER in forum Programming
    Replies: 7
    Last Post: 08-29-2017, 09:49 AM
  2. Generate Email Template from Form
    By ryancgarrett in forum Access
    Replies: 3
    Last Post: 09-22-2015, 05:19 PM
  3. Email Template IIF(Len) command
    By yframediscounts in forum Programming
    Replies: 1
    Last Post: 02-19-2015, 08:04 AM
  4. Replies: 6
    Last Post: 03-26-2014, 10:04 AM
  5. Send email using template
    By Kivan in forum Programming
    Replies: 1
    Last Post: 09-07-2012, 12:39 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