insert text from a text box into email.

jbs

Registered User.
Local time
Yesterday, 16:55
Joined
Sep 17, 2012
Messages
30
Hi all,

i currently have a code that creates an email with my desired text in the code, but i was wondering if there was a way to insert text from a text box (text will change) into my email as well?

Thanks
 
Yes you can. I am not sure how you are sending email.. But here is a (non tested) code..
Code:
Private Sub sendEmail_Btn_Click()
[COLOR=SeaGreen]'Define variables[/COLOR]
Dim strTo As String
Dim strSubject As String
Dim strMessage As String
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem

[COLOR=SeaGreen]'Assign values to defined variables[/COLOR]
strTo = Me.toAdd_Txt      [COLOR=SeaGreen]'  toAdd_Txt will ideally be the Text field for EMAIL addeess on the Form[/COLOR]
strSubject = Me.mailSub_Txt      [COLOR=SeaGreen]'  mailSub_Txt will ideally be the Text field for Subject on the Form[/COLOR].
strMessage = Me.mailBody_Txt      [COLOR=SeaGreen]'  mailBody_Txt will ideally be the Text field for the content you wish to send off from the Form.[/COLOR]

[COLOR=SeaGreen]'Create message[/COLOR]
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

[COLOR=SeaGreen]'Send the message[/COLOR]
With objOutlookMsg
    objOutlookMsg.To = strTo
    objOutlookMsg.Subject = strSubject
    objOutlookMsg.Body = strMessage
    objOutlookMsg.BodyFormat = olFormatHTML
    objOutlookMsg.Importance = olImportanceNormal
    objOutlookMsg.Send
End With
Set objOutlook = Nothing
End Sub
 
Thanks pr2,

My current code that works is below. This generates an email based on checkboxes i have checked with Hi, always included. I just need a code that will pick up the text box on the form to insert between the "Hi," and 'Text1"

Code:
Private Sub Command35_Click()
Dim strText As String
strText = "Hi,"
strText = strText & vbCrLf & vbCrLf & "Text1"
If checkbox1 = True Then
strText = strText & vbCrLf & vbCrLf & "Text2"
End If
If Check29 = True Then
strText = strText & vbNewLine & "Text3"
End If
If Check31 = True Then
strText = strText & vbNewLine & "Text4"
End If
DoCmd.SendObject acSendNoObject, "", actext, "[EMAIL="bruce.muscat@bendigoadelaide.com.au"]email at email.com[/EMAIL]", "", , "Subject1", strText
End Sub
 
Hi.. I believe Text1, Text2 are names of text boxes on the form.. So they do not have to be surrounded by "".. If they are surrounded by "" then it becomes a String.. So change your code to..
Code:
Private Sub Command35_Click()
    Dim strText As String
    strText = "Hi,"
    strText = strText & vbCrLf & vbCrLf & Me.Text1
    
    If Me.checkbox1 = True Then    strText = strText & vbCrLf & vbCrLf & Me.Text2
    If Me.Check29 = True Then    strText = strText & vbNewLine & Me.Text3
    If Me.Check31 = True Then    strText = strText & vbNewLine & Me.Text4

    DoCmd.SendObject acSendNoObject, "", actext, "username@email.com", "", , "Subject1", strText
End Sub
 
Thanks again!

"Text 1,2,3" etc inside the " " are pre determined and will never change (sorry for the confusion).

So if i am reading this right i will just need to enter:

Code:
strText = strText & vbCrLf & vbCrLf & Me.Textbox1

and that should insert whatever is in Textbox1 into the email?
 

Users who are viewing this thread

Back
Top Bottom