I am building an Access database and am putting some final touches on it before it is rolled out. My users want to be able to click a button that will shoot off an email to their supervisor. I added a command button to one of the forms and added code to visual basic (see below). When I run a test, I receive a Compile error message, "User-defined type not defined." I click ok and objOutlook As Outlook.Application is highlighted in blue in Visual Basic for Applications screen. Any thoughts as to how I might be able to resolve this. Also, if you happen to have better code that would be great.
Here is the code that I am using:
Private Sub Command316_Click()
Dim strEmail, strBody As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Set objOutlook = CreateObject("Outlook.Application")
DoEvents
Set objEmail = objOutlook.CreateItem(olMailItem)
DoEvents
strEmail = "supervisor@email.com"
strBody = "A new extension request is ready for your approval. Please login to DPDS and have a nice day."
DoEvents
With objEmail
DoEvents
.To = strEmail
DoEvents
.Subject = me.complaint#
DoEvents
.Body = strBody
DoEvents
.Send
End With
Set objEmail = Nothing
Exit Sub
End Sub
Here is the code that I am using:
Private Sub Command316_Click()
Dim strEmail, strBody As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Set objOutlook = CreateObject("Outlook.Application")
DoEvents
Set objEmail = objOutlook.CreateItem(olMailItem)
DoEvents
strEmail = "supervisor@email.com"
strBody = "A new extension request is ready for your approval. Please login to DPDS and have a nice day."
DoEvents
With objEmail
DoEvents
.To = strEmail
DoEvents
.Subject = me.complaint#
DoEvents
.Body = strBody
DoEvents
.Send
End With
Set objEmail = Nothing
Exit Sub
End Sub