I created a test database to test sending email from Access. Everything works great on my test database on C:. When I copy the form/code/query to the database on our network I get this error: "The expression On Click you entered as the event property setting produced the following error: User-defined type not defined."
When I compile it stops on this line: "Dim objOutlook As Outlook.Application"
I don't understand. I'm running this on the same PC. What could be the problem?
Here is the code that resides in the On Click event. It is the only code on the form.
Private Sub Command0_Click()
Dim EmlTo As String
Dim EmlSubject As String
Dim dbs As Database
Dim rst As DAO.Recordset
Dim stDocName As String
Dim StrAttach As String
Dim strHTML
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("qryEmail")
With rst
If .RecordCount <> 0 Then
Do While Not rst.EOF
StrAttach = "k:\restrict\techmdb\procure\email\readme.pdf"
stDocName = "Invitation From St Paul PHA Maintenance Contracts"
' DoCmd.OpenReport stDocName, acViewPreview, , "[MANAGERID] ='" & rst("MANAGERID") & "'"
' DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, StrAttach, False
' DoCmd.Close acReport, stDocName
Set objEmail = objOutlook.CreateItem(olMailItem)
EmlTo = rst("Email")
EmlSubject = "Invitation From St Paul PHA Maintenance Contracts"
strHTML = ""
strHTML = strHTML & "<br />"
strHTML = strHTML & "<FONT Face=Arial Size=2>Please open the attached file. </FONT><br />"
strHTML = strHTML & "<br />"
strHTML = strHTML & "<FONT Face=Arial Size=2>Thank you,<br />"
strHTML = strHTML & "<br />"
strHTML = strHTML & "<FONT Face=Arial Size=2><i><b>Saint Paul Public Housing Agency<br />"
strHTML = strHTML & "<FONT Face=Arial Size=2>Maintenance Contracts Department<br />"
strHTML = strHTML & "<FONT Face=Arial Size=2>651-292-6606<br />"
With objEmail
.To = EmlTo
.Subject = EmlSubject
.Attachments.Add StrAttach
.Importance = 2 ' olImportanceHigh
.HTMLBody = strHTML
.Send 'change to .Send to auto-send all emails
End With
.MoveNext
' Kill StrAttach
Loop
End If
End With
MsgBox "Emails Have Been Sent"
End Sub
When I compile it stops on this line: "Dim objOutlook As Outlook.Application"
I don't understand. I'm running this on the same PC. What could be the problem?
Here is the code that resides in the On Click event. It is the only code on the form.
Private Sub Command0_Click()
Dim EmlTo As String
Dim EmlSubject As String
Dim dbs As Database
Dim rst As DAO.Recordset
Dim stDocName As String
Dim StrAttach As String
Dim strHTML
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("qryEmail")
With rst
If .RecordCount <> 0 Then
Do While Not rst.EOF
StrAttach = "k:\restrict\techmdb\procure\email\readme.pdf"
stDocName = "Invitation From St Paul PHA Maintenance Contracts"
' DoCmd.OpenReport stDocName, acViewPreview, , "[MANAGERID] ='" & rst("MANAGERID") & "'"
' DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, StrAttach, False
' DoCmd.Close acReport, stDocName
Set objEmail = objOutlook.CreateItem(olMailItem)
EmlTo = rst("Email")
EmlSubject = "Invitation From St Paul PHA Maintenance Contracts"
strHTML = ""
strHTML = strHTML & "<br />"
strHTML = strHTML & "<FONT Face=Arial Size=2>Please open the attached file. </FONT><br />"
strHTML = strHTML & "<br />"
strHTML = strHTML & "<FONT Face=Arial Size=2>Thank you,<br />"
strHTML = strHTML & "<br />"
strHTML = strHTML & "<FONT Face=Arial Size=2><i><b>Saint Paul Public Housing Agency<br />"
strHTML = strHTML & "<FONT Face=Arial Size=2>Maintenance Contracts Department<br />"
strHTML = strHTML & "<FONT Face=Arial Size=2>651-292-6606<br />"
With objEmail
.To = EmlTo
.Subject = EmlSubject
.Attachments.Add StrAttach
.Importance = 2 ' olImportanceHigh
.HTMLBody = strHTML
.Send 'change to .Send to auto-send all emails
End With
.MoveNext
' Kill StrAttach
Loop
End If
End With
MsgBox "Emails Have Been Sent"
End Sub