Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Access Send Email Using Command Button

Status
Not open for further replies.

Cbohandy

Technical User
Jul 22, 2014
2
US
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
 
You probably need to add the Microsoft Outlook Object Library to the Tools->References.

From any VBA window, select Tools->References and scroll down to find the appropriate Microsoft Outlook ##.# Library. Click to add a check mark and then click OK to close. Then click Debug->Compile... to make sure your codes is mostly good.

Duane
Hook'D on Access
MS Access MVP
 
Why not simply use the SendObject method ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
dhookom it worked thank you.

Hook'D I didn't think of SendObject, I'll give it a try.

Thank you,

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top