Is it possible to have the code changed to send the emails from a different outlook email address. this is my code..
I get this to work by creating a second profile in outlook and select that and it send correct but looking for a way now to have the code do this so the user doent need to do this
I get this to work by creating a second profile in outlook and select that and it send correct but looking for a way now to have the code do this so the user doent need to do this
Code:
Dim MyDB As Database
Dim MyRS As Recordset
Dim MyForm As Form
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim TheAddress As String
Dim TheBody As String
Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset("test")
MyRS.MoveFirst
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
Do Until MyRS.EOF
' Create the e-mail message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
TheAddress = MyRS![Email]
TheBody ="<p style='font-family:Tahoma;'>Account Number: " & MyRS![Customer_Number] & _
"<p style='font-family:Tahoma;'>Hi " & MyRS![Forename] & " <sp> " & MyRS![Surname] & _
"<p style='font-family:Tahoma;'>Test Here</p>" & _
"<p style='font-family:Tahoma;'>Test Here</p>" & _
"<p style='font-family:Tahoma;'>Test Here</p>" & _
"<p style='font-family:Tahoma;'>Test Here</p>" & _
"<p style='font-family:Tahoma;'>Test Here</p>" & _
"<h2 style='text-align:Left;'><strong></strong></h2>"
With objOutlookMsg
' Add the To recipients to the e-mail message.
Set objOutlookRecip = .Recipients.Add(TheAddress)
objOutlookRecip.Type = olBCC
' Set the Subject, the Body, and the Importance of the e-mail message.
.To = TheAddress
.Subject = "Test"
.HTMLBody = TheBody
' Resolve the name of each Recipient.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send
End With
MyRS.MoveNext
Loop
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub