Hi:
I am writing some code to automatically send an Outlook email with information from an Access form. The test database works fine but when putting my code into the production database I get this error. I've seen advice on enabling the DAO Object Library; however I am not an administrator on my computer so I can't enable it. When I try to enable it from someone's account who is an admin, I get the "name conflicts with existing module, project or object library." I'm not sure this is even the problem, as I can get it to work on my machine without the DAO object library.
The error is at:
Dim objOutlook As outlook.Application
I don't program; everything I've done here is from Google and a little bit of tech knowledge. So any advice I probably need dumbed-down. Any help is GREATLY appreciated!
Regards,
Miranda
P.S. I'm so sorry - it looks like I have to paste the code right in the post.
Private Sub Box46_Click()
Dim email As String
Dim origin As String
Dim ref As String
Dim notes As String
Dim strBody As String
Dim strBody2 As String
Dim workOrder As Variant
Dim Building As String
Dim (a bunch of facility managers) as String
‘ right here I define all the facility managers with their emails
Dim objOutlook As outlook.Application
Dim objEmail As outlook.MailItem
email = Me!email
ref = Me!ref
notes = Me!notes
If Me!workOrder = notNull Then
workOrder = Me!workOrder
Else
workOrder = "N/A"
End If
If Me!Building = notNull Then
Building = Me!Building
Else
Building = "N/A"
End If
' Resolve each Recipient's name.
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(outlookMailItem)
strBody = "Thank you for contacting DTMB Customer Service Center. Work order number " & workOrder & " has been created for your most recent request:" & vbNewLine & vbNewLine & "Request Details: " & notes
strBody2 = "If you have questions relating to this request, please reference the work order number when you contact the DTMB Customer Service Center at REDACTED." & vbNewLine & vbNewLine & "Thank you!"
With objEmail
.To = email
.SentOnBehalfOfName = "DTMB-customerservice@REDACTED"
.Subject = ref & "Request"
.Body = strBody & vbNewLine & vbNewLine & strBody2
' Add the CC recipient(s) to the message.
If Building = "Hannah Building" Or Building = "Ottawa Building" Or Building = "Hall of Justice" Then
.CC = FS
Else
If Building = "Constitution Hall" Or Building = "Van Wagoner Building" Or Building = "Williams Building" Then
.CC = FS
Else
If Building = "Austin Building" Or Building = "Joint Operations Center" Or Building = "MLHC" Or Building = "Mason Building" Then
.CC = FS
Else
If Building = "Cass Building" Or Building = "Romney Building" Or Building = "Lottery Building" Then
.CC = FS
Else
If Building = "MSP HQ" Or Building = "Grand Tower Building" Or Building = "Joint Lab" Then
.CC = FS
Else
If Building = "Cadillac Place" Then
.CC = FS
Else
If Building = "Energy Center" Or Building = "HAZMAT" Or Building = "MDOT Photo Lab" Or Building = "General Services Building" Or Building = "MDOT Warehouse" Or Building = "Operations Center" Or Building = "Vehicle Travel Services" Then
.CC = FS
Else
If Building = "General Office Building" Or Building = "MSP Forensic Center" Or Building = "MDOT C&T" Or Building = "Secretary of State Building" Or Building = "MSP Training Academy" Or Building = "MSP 1st District HQ" Then
.CC = FS
Else
If Building = "Flint SOB" Or Building = "Saginaw SOB" Then
.CC = FS
Else
If Building = "Jackson SOB" Then
.CC = FS
Else
If Building = "Traverse City SOB" Then
.CC = FS
Else
If Building = "Escanaba SOB" Or Building = "Grand Rapids SOB" Then
.CC = FS
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
.Display 'sends the email in Outlook. Change to DISPLAY if you want to be able to
'modify or see what you have created before sending the email
End With
End Sub
I am writing some code to automatically send an Outlook email with information from an Access form. The test database works fine but when putting my code into the production database I get this error. I've seen advice on enabling the DAO Object Library; however I am not an administrator on my computer so I can't enable it. When I try to enable it from someone's account who is an admin, I get the "name conflicts with existing module, project or object library." I'm not sure this is even the problem, as I can get it to work on my machine without the DAO object library.
The error is at:
Dim objOutlook As outlook.Application
I don't program; everything I've done here is from Google and a little bit of tech knowledge. So any advice I probably need dumbed-down. Any help is GREATLY appreciated!
Regards,
Miranda
P.S. I'm so sorry - it looks like I have to paste the code right in the post.
Private Sub Box46_Click()
Dim email As String
Dim origin As String
Dim ref As String
Dim notes As String
Dim strBody As String
Dim strBody2 As String
Dim workOrder As Variant
Dim Building As String
Dim (a bunch of facility managers) as String
‘ right here I define all the facility managers with their emails
Dim objOutlook As outlook.Application
Dim objEmail As outlook.MailItem
email = Me!email
ref = Me!ref
notes = Me!notes
If Me!workOrder = notNull Then
workOrder = Me!workOrder
Else
workOrder = "N/A"
End If
If Me!Building = notNull Then
Building = Me!Building
Else
Building = "N/A"
End If
' Resolve each Recipient's name.
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(outlookMailItem)
strBody = "Thank you for contacting DTMB Customer Service Center. Work order number " & workOrder & " has been created for your most recent request:" & vbNewLine & vbNewLine & "Request Details: " & notes
strBody2 = "If you have questions relating to this request, please reference the work order number when you contact the DTMB Customer Service Center at REDACTED." & vbNewLine & vbNewLine & "Thank you!"
With objEmail
.To = email
.SentOnBehalfOfName = "DTMB-customerservice@REDACTED"
.Subject = ref & "Request"
.Body = strBody & vbNewLine & vbNewLine & strBody2
' Add the CC recipient(s) to the message.
If Building = "Hannah Building" Or Building = "Ottawa Building" Or Building = "Hall of Justice" Then
.CC = FS
Else
If Building = "Constitution Hall" Or Building = "Van Wagoner Building" Or Building = "Williams Building" Then
.CC = FS
Else
If Building = "Austin Building" Or Building = "Joint Operations Center" Or Building = "MLHC" Or Building = "Mason Building" Then
.CC = FS
Else
If Building = "Cass Building" Or Building = "Romney Building" Or Building = "Lottery Building" Then
.CC = FS
Else
If Building = "MSP HQ" Or Building = "Grand Tower Building" Or Building = "Joint Lab" Then
.CC = FS
Else
If Building = "Cadillac Place" Then
.CC = FS
Else
If Building = "Energy Center" Or Building = "HAZMAT" Or Building = "MDOT Photo Lab" Or Building = "General Services Building" Or Building = "MDOT Warehouse" Or Building = "Operations Center" Or Building = "Vehicle Travel Services" Then
.CC = FS
Else
If Building = "General Office Building" Or Building = "MSP Forensic Center" Or Building = "MDOT C&T" Or Building = "Secretary of State Building" Or Building = "MSP Training Academy" Or Building = "MSP 1st District HQ" Then
.CC = FS
Else
If Building = "Flint SOB" Or Building = "Saginaw SOB" Then
.CC = FS
Else
If Building = "Jackson SOB" Then
.CC = FS
Else
If Building = "Traverse City SOB" Then
.CC = FS
Else
If Building = "Escanaba SOB" Or Building = "Grand Rapids SOB" Then
.CC = FS
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
.Display 'sends the email in Outlook. Change to DISPLAY if you want to be able to
'modify or see what you have created before sending the email
End With
End Sub