Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pre-select the Outlook From Mail account in sending email thru MS Access

Status
Not open for further replies.

ctopia88

IS-IT--Management
Jun 24, 2012
12
AE
Hi,

We have a working module in MsAccess which code is for sending email thru Outlook. What we have done is when a "Generate Email" button is clicked, it will call the email module whose function is to create an email thru outlook. We will then choose manually which E-mail account to use and then we send it.
Is there a way to pre-select the E-mail account to use so that we don't need to manually choose?
Below is our simple code:

Public Function SendEMail()
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim Subjectline As String
Dim BodyFile As String
Dim MyBodyText As String
Subjectline$ = "Test"

MyBodyText = "<table border='0'style='font-family: Arial; font-size:13'><tr><td></td></tr>"
MyBodyText = MyBodyText & "<tr><td>Body of Msg</td><td width='100' align='center'>:</td><td>" & Form_Test.Body & "</td></tr>" & "<tr><td colspan='3' height='25'></td></tr>"

Set MyOutlook = New Outlook.Application

Set MyMail = MyOutlook.CreateItem(olMailItem)
MyMail.To = "me@yahoo.com"
MyMail.Subject = Subjectline$
MyMail.HTMLBody = MyBodyText
MyMail.Display
Set MyMail = Nothing
Set MyOutlook = Nothing
End Function

Thanks
 
this is sub that I use to send emails....it bypasses outlook itself and goes directly to/throught the email server. The Bad part is that you have nothing in your sent items using this sub. You can pass in parameters like I've done OR hardcode the parts you want...

Sub SendEmail(ToName, SendFile, AboutName, ReportType)

Dim EmailTo As String, MessageBody As String, SubjectLine As String
Dim objmessage As Object
Dim i As Integer

Set objmessage = CreateObject("CDO.Message")
objmessage.Subject = SubjectLine
objmessage.From = "123@abc.com" ' Enter the email address you want or pass as parameter
'objmessage.cc = "456@DEF.com"
objmessage.To = ToName 'passed as a parameter

objmessage.AddAttachment SendFile

objmessage.TextBody = MessageBody
objmessage.Configuration.Fields.Item _
(" = 2
objmessage.Configuration.Fields.Item _
(" = "youremailserver.yourcompany.com"
objmessage.Configuration.Fields.Item _
(" = 25
objmessage.Configuration.Fields.Update
objmessage.Send

End Sub

Be Alert, America needs more lerts
 
Also...not to put to fine a point on it....but you might receive more responses by posting this in the VBA group versus the generic Office...since it's looks like a VBA solution....HTH

Be Alert, America needs more lerts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top