Hi all,
I am have a question concerning the use of the SendObject function. I am using a database that has two buttons to send e-mails. The first button sends an e-mail with text that it gets from an open form, and the second button sends an email with a report as a PDF attached. This database is used on several computers at our offices, and the problem is the that first button works on all the computers; however, the second only works on about half of them.
I thought maybe the email client was not set up properly, but button 1 works so that leads me to discredit that notion. The only other difference I see is that button 2 involves a report which might be the cause of the issue. I'm wondering if anybody knows why this is happening and how to fix it or a different approach that would circumvent the problem
Code for button 1:
Private Sub SendEmailToAssignedTo_Click()
'Variables to hold e-mail addresses
Dim ToEmailAddress As String
Dim AffectedBy1 As String
Dim AffectedBy2 As String
Dim AffectedBy3 As String
Dim CCEmailAddresses As String
'Assign the Assigned To email adress to a variable
ToEmailAddress = IIf([Assigned To] = 17, "", Nz(DLookup("[EMailAddress]", "Contacts", "ID=" & Nz([Assigned To], 0))))
'Assign the affected by e-mail addresses to variables
AffectedBy1 = IIf([Affected By-1] = 17, "", Nz(DLookup("[E-Mail Address]", "Contacts", "ID=" & Nz([Affected By-1], 0))))
AffectedBy2 = IIf([Affected By-2] = 17, "", Nz(DLookup("[E-Mail Address]", "Contacts", "ID=" & Nz([Affected By-2], 0))))
AffectedBy3 = IIf([Affected By-3] = 17, "", Nz(DLookup("[E-Mail Address]", "Contacts", "ID=" & Nz([Affected By-3], 0))))
'Combine all threee email address into one variable adding semicolons if necessary
If AffectedBy1 <> "" Then
CCEmailAddresses = AffectedBy1
End If
If AffectedBy2 <> "" And AffectedBy1 <> "" Then
CCEmailAddresses = CCEmailAddresses & "; " & AffectedBy2
ElseIf AffectedBy2 <> "" Then
CCEmailAddresses = AffectedBy2
End If
If AffectedBy3 <> "" And AffectedBy2 <> "" And AffectedBy1 <> "" Then
CCEmailAddresses = CCEmailAddresses & "; " & AffectedBy3
ElseIf AffectedBy3 <> "" And AffectedBy2 <> "" Then
CCEmailAddresses = CCEmailAddresses & "; " & AffectedBy3
ElseIf AffectedBy3 <> "" And AffectedBy1 <> "" Then
CCEmailAddresses = CCEmailAddresses & "; " & AffectedBy3
ElseIf AffectedBy3 <> "" Then
CCEmailAddresses = AffectedBy3
End If
'Allows proper operation if e-mail is closed without sending
On Error Resume Next
'Sends information to default e-mail program
DoCmd.SendObject , , , ToEmailAddress, _
CCEmailAddresses, "mmccoy@hunter.com; slochmann@hunter.com", "ECO# " & [Title], _
[Forms]![Issues]![ECO Description] & "; " & [Forms]![Issues]![Comment], True
End Sub
Code for Button 2:
Private Sub cmdSendEmail_Click()
'Variable to hold email address
Dim strToEmailAddress As String
'Get email address
strToEmailAddress = Nz(DLookup("[E-Mail Address]", "Contacts", "ID=" & Nz([cboSendEmailTo], 0)))
'Ensures proper operation if email is closed without saving
On Error Resume Next
'Sends Email
DoCmd.SendObject acSendReport, "Issue Details By Assigned", acFormatPDF, strToEmailAddress, , , _
"Issues Report", "Issues Report is attached", True
'Closes form
'DoCmd.Close acForm, Me.Name
End Sub
Thanks in advance