Results 1 to 4 of 4
  1. #1
    TerraEarth is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    86

    User-inputted email messages (with formatting?)

    If I had a database where mass emails were sent out with a template email body, what would be the best and simplest way to allow users to change the body?



    Currently I use html to build the email body complete with formatting (colors, fonts, italics, underlines, etc.) and feed it to vba as a string. If the user wanted to change the body themselves they could either change the html code directly or feed a string into the DB through some kind of prompt.

    However, is there a way to implement this feature to make it easy for the users to implement their own formatting to the message? Perhaps interfaced via Outlook or Microsoft Word? The only way I currently know of is if they feed a HTML string to some kind of msgbox input (problem being that the people using it probably wouldn't know HTML to begin with).

    What's possible here and what method would you all recommend me to use?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    You could keep a word file, (as html doc) on the server.
    I have a table tConfig, w field : EBody
    it has the path: \\server\folder\eBody.htm


    user can click a button on the form to edit, it opens the document via:
    OpenNativeApp txtBox
    (see code below)
    then the document can be added to the body of email via:








    paste this code into a module. (Alt-F11, insert , module)
    Then it will open ANY file via its extension....
    .pdf files will open in acrobat,
    .doc files in word
    etc


    USAGE:
    OpenNativeApp "c:\folder\file.xls"
    'opens in excel
    or
    OpenNativeApp field
    'opens item in field in native app


    Code:
    Option Compare Database
    Option Explicit
    
    
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Const SW_SHOWNORMAL = 1
    Const SE_ERR_FNF = 2&
    Const SE_ERR_PNF = 3&
    Const SE_ERR_ACCESSDENIED = 5&
    Const SE_ERR_OOM = 8&
    Const SE_ERR_DLLNOTFOUND = 32&
    Const SE_ERR_SHARE = 26&
    Const SE_ERR_ASSOCINCOMPLETE = 27&
    Const SE_ERR_DDETIMEOUT = 28&
    Const SE_ERR_DDEFAIL = 29&
    Const SE_ERR_DDEBUSY = 30&
    Const SE_ERR_NOASSOC = 31&
    Const ERROR_BAD_FORMAT = 11&
    
    
    Public Sub OpenNativeApp(ByVal psDocName As String)
    Dim r As Long, msg As String
    
    
    r = StartDoc(psDocName)
    If r <= 32 Then
        'There was an error
        Select Case r
            Case SE_ERR_FNF
                msg = "File not found"
            Case SE_ERR_PNF
                msg = "Path not found"
            Case SE_ERR_ACCESSDENIED
                msg = "Access denied"
            Case SE_ERR_OOM
                msg = "Out of memory"
            Case SE_ERR_DLLNOTFOUND
                msg = "DLL not found"
            Case SE_ERR_SHARE
                msg = "A sharing violation occurred"
            Case SE_ERR_ASSOCINCOMPLETE
                msg = "Incomplete or invalid file association"
            Case SE_ERR_DDETIMEOUT
                msg = "DDE Time out"
            Case SE_ERR_DDEFAIL
                msg = "DDE transaction failed"
            Case SE_ERR_DDEBUSY
                msg = "DDE busy"
            Case SE_ERR_NOASSOC
                msg = "No association for file extension"
            Case ERROR_BAD_FORMAT
                msg = "Invalid EXE file or error in EXE image"
            Case Else
                msg = "Unknown error"
        End Select
    '    MsgBox msg
    End If
    End Sub
    
    
    Private Function StartDoc(psDocName As String) As Long
    Dim Scr_hDC As Long
    
    
    Scr_hDC = GetDesktopWindow()
    StartDoc = ShellExecute(Scr_hDC, "Open", psDocName, "", "C:\", SW_SHOWNORMAL)
    End Function

    text box is set to TEXT FORMAT property = RICH TEXT

    run code to open the Edoc.htm
    copy the text
    then paste the doc into the text box: DoCmd.RunCommand acCmdPaste
    then send email

    usage:
    Email1 "W.Coyote@acme.com","Anvils", txtBody




    Code:
    
    Public Function Email1(ByVal pvTo, ByVal pvSubj, ByVal pvBody, Optional ByVal pvFile) As Boolean
    Dim oApp As Outlook.Application
    Dim oMail As Outlook.MailItem
    
    
    On Error GoTo ErrMail
    
    
    'NOTE : YOU MUST HAVE THE OUTLOOK REFERENCE CHECKED IN VBE; ctl-G, menu,tools, references, Microsoft Outlook XX Object library
    Set oApp = CreateObject("Outlook.Application")
    Set oMail = oApp.createitem(olmailitem)
    
    
    With oMail
        .To = pvTo
        .Subject = pvSubj
          ''If Not IsNull(pvBody) Then .Body = pvBody
        .HTMLBody = pvBody
        If Not IsMissing(pvFile) Then .Attachments.Add pvFile, olByValue, 1
        
        '.Display True
        .Send
    End With
    
    
    Email1 = True
    Endit:
    Set oMail = Nothing
    Set oApp = Nothing
    Exit Function
    
    
    ErrMail:
    MsgBox Err.Description, vbCritical, Err
    Resume Endit
    End Function

  3. #3
    TerraEarth is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    86
    This looks great, I'll review it thoroughly and see if I could implement/adapt it for on my Database.

    Did you mean to insert a code clip below your second paragraph?

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    1 block is used to open any document; word, pdf, xl, etc
    and the other is to use email to post the textbox into the email, after loading it from the word doc.

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

Similar Threads

  1. Replies: 6
    Last Post: 02-26-2018, 07:16 AM
  2. Replies: 1
    Last Post: 12-20-2016, 10:09 PM
  3. Replies: 1
    Last Post: 06-25-2015, 01:12 PM
  4. Replies: 3
    Last Post: 11-14-2014, 02:51 PM
  5. SENDING EMAIL MESSAGES DIRECTLY FROM ACCESS
    By Frenchos in forum Access
    Replies: 0
    Last Post: 07-20-2007, 12:51 AM

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