I am using the following code to create and send an email. It works great.
My challenge is that I am trying to use the code again within the same db on a different form, but no luck. I get no response at all when I execute the Click event. I am using the same variables but assigning different fields to the variables. I tried renaming variable and object names but also, no luck.
I am not sure why it would not work, can someone advise.
Thanks.
Joel
CODE:
Private Sub cmdSendEmail_Click()
'Just a message to make sure the user is using a valid email address.
RetValue = MsgBox("1. Are you sure the Requestor's email address is valid?" & Chr(13) _
& "2. Have you entered a response to the requestor?", vbOKCancel)
If RetValue = 1 Then
'******begin code******
Dim email, ref, origin, destination, notes, Desc As String
Dim objOutlook As Object 'Outlook.Application
Dim objEmail As Object 'Outlook.MailItem
'
'**gathers information from your form. this sets the string variable to your fields
email = Me!email
ref = Me.Topic
notes = Me!notes
Desc = Me.Q4433.Value
'***creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.application"
Set objEmail = objOutlook.CreateItem(olMailItem)
'***creates and sends email
With objEmail
.to = email
.Subject = ref '& " " & origin & " " & destination
.Body = "1. Message from SDG POC: " & notes & Chr(13) _
& "2. Description from Request Form: " & Desc
.Send
End With
'
'**closes outlook
Set objEmail = Nothing
'The next line is commented out to eliminate the closing of MS Outlook
'I have commented the following line out to prevent outlook from closing.
'objOutlook.Quit
'
Exit Sub
'****end code****
Else
Exit Sub
End If
End Sub
My challenge is that I am trying to use the code again within the same db on a different form, but no luck. I get no response at all when I execute the Click event. I am using the same variables but assigning different fields to the variables. I tried renaming variable and object names but also, no luck.
I am not sure why it would not work, can someone advise.
Thanks.
Joel
CODE:
Private Sub cmdSendEmail_Click()
'Just a message to make sure the user is using a valid email address.
RetValue = MsgBox("1. Are you sure the Requestor's email address is valid?" & Chr(13) _
& "2. Have you entered a response to the requestor?", vbOKCancel)
If RetValue = 1 Then
'******begin code******
Dim email, ref, origin, destination, notes, Desc As String
Dim objOutlook As Object 'Outlook.Application
Dim objEmail As Object 'Outlook.MailItem
'
'**gathers information from your form. this sets the string variable to your fields
email = Me!email
ref = Me.Topic
notes = Me!notes
Desc = Me.Q4433.Value
'***creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.application"
Set objEmail = objOutlook.CreateItem(olMailItem)
'***creates and sends email
With objEmail
.to = email
.Subject = ref '& " " & origin & " " & destination
.Body = "1. Message from SDG POC: " & notes & Chr(13) _
& "2. Description from Request Form: " & Desc
.Send
End With
'
'**closes outlook
Set objEmail = Nothing
'The next line is commented out to eliminate the closing of MS Outlook
'I have commented the following line out to prevent outlook from closing.
'objOutlook.Quit
'
Exit Sub
'****end code****
Else
Exit Sub
End If
End Sub