sending email using dynamic body text

mosheva

New member
Local time
Yesterday, 20:45
Joined
Mar 19, 2012
Messages
7
Hello!
I'm trying to create a send via email function that will use specific body template that is also field with the data from the current form that is opened.

Now i'm using the Do.Cmd.Sendobject function but it is very limited as I want to be able to use the BOLD function on certain fields or highlight a text.
Plus I reach the limit of characters and cannot add more fields to the template.
here is the current code:

Code:
Private Sub email_Click()
messageText = "Dear ," & vbCrLf & "Please find the following description for a suspected problem that occurred in " + LocationTxt.Value + " on " + RunwayCombo.Value + " SDU # " + SduCombo.Value + " " + "During Date/Time" & vbCrLf & "The following SR ID# <_>" + "is Opened in the SR Tool-CRM system. Case severity is " + SevirityTxt.Value & vbCrLf & "" & vbCrLf & "Description:" & vbCrLf & Description.Value & vbCrLf & " " & vbCrLf & "Additional*information:" & vbCrLf & Additional*information.Value & vbCrLf & "" & vbCrLf & "Please add resolution below:" & vbCrLf & "" & vbCrLf & "This case is assigned to: " + GsocEmployeeCombo.Value & vbCrLf & "Please keep us updated for the progress of investigation." & vbCrLf & "" & vbCrLf & "Regards," & vbCrLf
Subject = "Escalation"

DoCmd.SendObject , , , , , , Subject, messageText, , ""
End Sub



Any guide will be highly appreciated!

Regards,
Moshes.
 
See this, there you will find several methods of sending emails.
 
Hello!
I look at the link but haven't found what I'm looking for...
I thought about sending a report but if I'm using the access email tool I either get the full report of all the table or get the report as attach file.

Can I build a custom report that will not show as attach file?

Edit:
I found this next code can I make it work with HTML?
Code:
Private Sub cmdEmail_Click()

Dim sTo As String
Dim sCC As String
Dim sBCC As String
Dim sSub As String
Dim sBody As String
Dim strCC As String
Dim OutApp As Object
Dim OutMail As Object
Dim varPress As Variant

strMess = "You are about to send an email message to the current user." & vbCrLf & vbCrLf
strMess = strMess & "Do you wish to continue?"

strStyle = vbYesNo
strTitle = "Send Notificaiton"

varPress = MsgBox(strMess, strStyle, strTitle)
If varPress = vbYes Then
    ' Get the email address from the current form control
    sTo = Me.EmailAddress
    
    '  Set the subject 
    sSub = "Some subject matter"

    ' Build the body of the email
    sBody = Me.FirstName & vbCrLf & vbCrLf
    sBody = sBody & "Continue with message
    
    ' Create the email
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    sCC = ""
    sBCC = ""
    
  
    With OutMail
        .To = sTo
        .CC = sCC
        .BCC = sBCC
        .Subject = sSub
        .Body = sBody
        .Display          ' THis will display the email, but not send it
        '.Send            ' THis will send the email
    End With
    Set OutMail = Nothing
    Set OutApp = Nothing
End If


End Sub

Please guide me through...

Best regards,
Moshes.
 
Last edited:
Thanks all!
I manage to do what I looked for...

Code:
Private Sub Mail_test3_Click()
    Dim olApp As Outlook.Application
    Dim objMail As Outlook.MailItem
    Set olApp = Outlook.Application
    'Create e-mail item
    Set objMail = olApp.CreateItem(olMailItem)

    With objMail
       'Set body format to HTML
       .BodyFormat = olFormatHTML
       .Subject = "Escalation - " & Me.LocationTxt & " - " & Me.SduCombo & " - " & Me.Failure & " - SR_" & Me.ID & " - " & Me.[Actual Open Date] & ""
       .HTMLBody = "<font face=Calibri><h3>Dear ,</h3> " _
       & "Please find the following description for a suspected problem that occurred in <b> " & Me.LocationTxt & "</b> on <b>" & Me.RunwayCombo & "</b> SDU <b>" & Me.SduCombo & "</b> during <b>" & Me.[Actual Open Date] & " " & Me.[Actual Open Time] & "</b>.<br /> " _
       & "Failure: <b>" & Me.Failure & "</b><br /> " _
       & "The following SR id# <b>" & Me.ID & "</b> is <b>" & Me.StatusCombo & "</b> in the SR tool-CRM system.<br />Case severity is <b>" & Me.SevirityTxt & "</b> " _
       & "<p><b>Description</b><br /> " & Me.Description & "" _
       & "<p><b>Additional information:</b><br />" & Me.Additional*information & "" _
       & "<p><b>Initial steps that has been done to solve the failure:</b><br />" & Me.Resolution & "" _
       & "<p><b>Please add the root cause analysis below:</b><br /><table width=600 border=1><td style=background-color:#eeeeee;height:200px;width:400px;text-align:left;>Content goes here</td></tr></table>  " _
       & "<p>This case is assigned to: <b>" & Me.[Gsoc Employee] & "</b><br />" _
       & "<p>Regards,<br />" & Me.[Gsoc Employee] & "<br/> GSOC Operator | "
       
       .Display
    End With

End Sub

Regards,
Moshes
 
Here is another way to send straight to server without using a mail program.

Code:
Public Function Emailer(strTo As String, strSubject As String, strBody As String,StrAttachment as string)

Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")
        iConf.Load -1    ' CDO Source Defaults
        Set Flds = iConf.Fields
        With Flds
            .Item("[URL]http://schemas.microsoft.com/cdo/configuration/sendusing[/URL]") = 2
            .Item("[URL]http://schemas.microsoft.com/cdo/configuration/smtpserver[/URL]") _
                            = "Enter your mail server here" 'something like mail.abc.com
                            
           .Item"[URL]http://schemas.microsoft.com/cdo/configuration/smtpserverport[/URL]") = 25
            .Update
        End With
    
    With iMsg
        Set .Configuration = iConf
        .To = strTo
        .CC = ""
        .BCC = ""
        .From = """From Me"" <[EMAIL="FromMe@ABC.com"]FromMe@ABC.com[/EMAIL]>"
        .Subject = strSubject
        .HTMLBody = strBody
        .AddAttachment = StrAttachment
        .Send
    End With
End Function
 
Hello Again!
Using the my code, how can I add attachment?
I want to be able to output a pdf file and then attach it to the new mail.
Here is the code again:

Code:
Private Sub Mail_test3_Click()
    Dim olApp As Outlook.Application
    Dim objMail As Outlook.MailItem
    Set olApp = Outlook.Application
    'Create e-mail item
    Set objMail = olApp.CreateItem(olMailItem)

    With objMail
       'Set body format to HTML
       .BodyFormat = olFormatHTML
       .Subject = "Escalation - " & Me.LocationTxt & " - " & Me.SduCombo & " - " & Me.Failure & " - SR_" & Me.ID & " - " & Me.[Actual Open Date] & ""
       .HTMLBody = "<font face=Calibri><h3>Dear ,</h3> " _
       & "Please find the following description for a suspected problem that occurred in <b> " & Me.LocationTxt & "</b> on <b>" & Me.RunwayCombo & "</b> SDU <b>" & Me.SduCombo & "</b> during <b>" & Me.[Actual Open Date] & " " & Me.[Actual Open Time] & "</b>.<br /> " _
       & "Failure: <b>" & Me.Failure & "</b><br /> " _
       & "The following SR id# <b>" & Me.ID & "</b> is <b>" & Me.StatusCombo & "</b> in the SR tool-CRM system.<br />Case severity is <b>" & Me.SevirityTxt & "</b> " _
       & "<p><b>Description</b><br /> " & Me.Description & "" _
       & "<p><b>Additional information:</b><br />" & Me.Additional*information & "" _
       & "<p><b>Initial steps that has been done to solve the failure:</b><br />" & Me.Resolution & "" _
       & "<p><b>Please add the root cause analysis below:</b><br /><table width=600 border=1><td style=background-color:#eeeeee;height:200px;width:400px;text-align:left;>Content goes here</td></tr></table>  " _
       & "<p>This case is assigned to: <b>" & Me.[Gsoc Employee] & "</b><br />" _
       & "<p>Regards,<br />" & Me.[Gsoc Employee] & "<br/> GSOC Operator | "
       
       .Display
    End With

End Sub

Regards,
Moshes.
 
Hi,
I getting a run time error '438' - Object doesn't support this property or method
 

Users who are viewing this thread

Back
Top Bottom