Link to home
Start Free TrialLog in
Avatar of filtrationproducts
filtrationproductsFlag for United States of America

asked on

Automate Email Message in Access 2003

I am trying to send an email through a button in Access. I programmed the button with the code attached in the snippet. Everytime I click the button I get the error (compile error: User Defined type not defined) on line:

    Dim appOutLook As Outlook.Application

Is there a way to fix this? Or does anyone else have an easier way to code a button to automatically send an email through Access/VB.

Dim appOutLook As Outlook.Application
    Dim MailOutLook As Outlook.MailItem
    Set appOutLook = CreateObject("Outlook.Application")
    Set MailOutLook = appOutLook.CreateItem(olMailItem)
    recipient = "" 'string ie..""
    With MailOutLook
        .To = recipient
        .Subject = msgSubject 'string ie.."Report"
        .body = msgBody 'string ie.."Your new report"
        .DeleteAfterSubmit = True   'This would let Outlook send the note without storing it in your sent bin
    End With
    Set MailOutLook = Nothing
    Set appOutLook = Nothing
    MailUser = ""
    msgSubject = "test"
    msgBody = "This email was sent via Access Databases"
    Exit Sub

Open in new window

Avatar of filtrationproducts
Flag of United States of America image


Here is a different one I downloaded as a sample and it works perfectly. Except when I copy the code to my database it gives me the same error

"compile error: User Defined type not defined"

But the sample database works fine and there is nothing special about it (no macro's or modules in the sample mdb)
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial