D
Denise
I am trying to use a button to send email with attachments
to different people all the time. Below is the code I am
using so far and I have two problems.
One is that I cannot get it to use an email address in my
Tblcontacts, field is named Email. Anyone know what I am
doing wrong?
Second, I keep getting a message from Microsoft Outlook
saying I am sending an email and you have to click yes or
no and I don't want to do that extra step.
Can anyone help?
Private Sub Command133_Click()
Dim strTo As String
Dim strsubject As String
Dim varbody As Variant
Dim strattachment1 As String
Dim strattachment2 As String
strTo = "([TblContact.Email])"
strsubject = "subject"
varbody = "Attached please find your confirmation"
strattachment1 = "name and location of attachment"
strattachment2 = "name and location of attachment"
Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")
Dim olNs As Outlook.NameSpace
Set olNs = olApp.GetNamespace("MAPI")
olNs.logon
Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)
olMail.To = strTo
olMail.subject = strsubject
olMail.body = varbody
If Len(strattachment1) <> 0 Then
olMail.Attachments.Add (strattachment1)
End If
If Len(strattachment2) <> 0 Then
olMail.Attachments.Add (strattachment2)
End If
olMail.Send
Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing
to different people all the time. Below is the code I am
using so far and I have two problems.
One is that I cannot get it to use an email address in my
Tblcontacts, field is named Email. Anyone know what I am
doing wrong?
Second, I keep getting a message from Microsoft Outlook
saying I am sending an email and you have to click yes or
no and I don't want to do that extra step.
Can anyone help?
Private Sub Command133_Click()
Dim strTo As String
Dim strsubject As String
Dim varbody As Variant
Dim strattachment1 As String
Dim strattachment2 As String
strTo = "([TblContact.Email])"
strsubject = "subject"
varbody = "Attached please find your confirmation"
strattachment1 = "name and location of attachment"
strattachment2 = "name and location of attachment"
Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")
Dim olNs As Outlook.NameSpace
Set olNs = olApp.GetNamespace("MAPI")
olNs.logon
Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)
olMail.To = strTo
olMail.subject = strsubject
olMail.body = varbody
If Len(strattachment1) <> 0 Then
olMail.Attachments.Add (strattachment1)
End If
If Len(strattachment2) <> 0 Then
olMail.Attachments.Add (strattachment2)
End If
olMail.Send
Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing