Code worked, now get error (1 Viewer)

LaurieW

Registered User.
Local time
Today, 15:19
Joined
May 9, 2002
Messages
99
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
 

BigHappyDaddy

Coding Monkey Wanna-Be
Local time
Today, 12:19
Joined
Aug 22, 2012
Messages
205
Maybe the Outlook reference library not set on computers running your database?
 

LaurieW

Registered User.
Local time
Today, 15:19
Joined
May 9, 2002
Messages
99
I'm running it on the same computer.
 

LaurieW

Registered User.
Local time
Today, 15:19
Joined
May 9, 2002
Messages
99
I just went into the References in the database that's not working and checked "Microsoft Outlook 12.0 Object Library" and now it works. I don't understand how the code could work in one and not the other on the same PC, but now it works so I'm good. :)
 

BigHappyDaddy

Coding Monkey Wanna-Be
Local time
Today, 12:19
Joined
Aug 22, 2012
Messages
205
References are set for each database, not for the computer. I have a number of database that may have the Outlook reference set, but if I am in a database that doesn't have that set, I would get the same error if I tried to reference an Outlook object.
 

LaurieW

Registered User.
Local time
Today, 15:19
Joined
May 9, 2002
Messages
99
Thank you for the explanation! It makes sense now.
 

Users who are viewing this thread

Top Bottom