Email problem

Discussion in 'Microsoft Access Form Coding' started by PsyberFox, May 14, 2010.

  1. PsyberFox

    PsyberFox Guest

    Hi there,

    I am getting an error stating User-defined type not defined when running the
    following code. I have activated References for Microsoft Office 12.0 Object
    Library as well as Microsoft Access 12.0 Object Library. This is in Access
    2007, and off a command button called cmd_Email

    Sub cmd_Email_Click()

    Dim objOutlook As Outlook.Application
    Dim objOutlookMessage As Outlook.MailItem
    Dim objOutlookRecipient As Outlook.Recipient
    Dim objOutlookAttach As Outlook.Attachment

    Set objOutlook = CreateObject("Outlook.Application")
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

    With objOutlookMessage
    ' Add the To recipient(s) to the message.
    Set objOutlookRecipient = .Recipients.Add("")
    objOutlookRecipient.Type = olTo

    ' Add the CC recipient(s) to the message.
    Set objOutlookRecipient = .Recipients.Add("")
    objOutlookRecipient.Type = olCC

    ' Set the Subject, Body, and Importance of the message.
    .Subject = "Test"
    .Body = PropertyRef & vbCrLf _
    & PropertyType & vbCrLf _
    & PropertyCategory & vbCrLf _
    & Description & vbCrLf _
    & Address1 & vbCrLf _
    & Address2 & vbCrLf _
    & Address3 & vbCrLf _
    & Active
    .Importance = olImportanceHigh 'High importance

    ' Add attachments to the message.
    ' If Not IsMissing(AttachmentPath) Then
    ' Set objOutlookAttach = .Attachments.Add(AttachmentPath)
    ' End If

    ' Resolve each Recipient's name.
    For Each objOutlookRecipient In .Recipients
    objOutlookRecipient.Resolve
    If Not objOutlookRecipient.Resolve Then
    objOutlookMessage.Display
    End If
    Next
    .Send

    End With

    Set objOutlookMessage = Nothing
    Set objOutlook = Nothing

    End Sub

    Please help! Thank you very mooch!

    --
    The Psyber Fox
    http://www.psyberconsulting.co.za
     
    PsyberFox, May 14, 2010
    #1
    1. Advertisements

  2. PsyberFox

    Dirk Goldgar Guest

    "PsyberFox" <> wrote in message
    news:...
    > Hi there,
    >
    > I am getting an error stating User-defined type not defined when running
    > the
    > following code. I have activated References for Microsoft Office 12.0
    > Object
    > Library as well as Microsoft Access 12.0 Object Library. This is in Access
    > 2007, and off a command button called cmd_Email
    >
    > Sub cmd_Email_Click()
    >
    > Dim objOutlook As Outlook.Application
    > Dim objOutlookMessage As Outlook.MailItem
    > Dim objOutlookRecipient As Outlook.Recipient
    > Dim objOutlookAttach As Outlook.Attachment


    [snip]

    Do you have a reference set to the Microsoft Outlook 12.0 Object Library?
    You'll need that if you're going to refer to Outlook-defined data types such
    as the above.

    As an alternative, you could forego the reference and use late binding by
    declaring all the Outlook-defined items as Object. You would also have to
    declare the constants olMailItem, olTo, olCC, and olImportanceHigh yourself,
    since those are defined by the Outlook object library. But if you don't
    mind having the reference to the Outlook library, you don't need to do that.

    --
    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    (please reply to the newsgroup)
     
    Dirk Goldgar, May 14, 2010
    #2
  3. PsyberFox

    PsyberFox Guest

    Hi,

    Yes I do have the reference to that object library, but still gives me the
    problem.

    Can you possible give me more details on the alternative?

    Thank you!
    W
    --
    The Psyber Fox
    http://www.psyberconsulting.co.za


    "Dirk Goldgar" wrote:

    > "PsyberFox" <> wrote in message
    > news:...
    > > Hi there,
    > >
    > > I am getting an error stating User-defined type not defined when running
    > > the
    > > following code. I have activated References for Microsoft Office 12.0
    > > Object
    > > Library as well as Microsoft Access 12.0 Object Library. This is in Access
    > > 2007, and off a command button called cmd_Email
    > >
    > > Sub cmd_Email_Click()
    > >
    > > Dim objOutlook As Outlook.Application
    > > Dim objOutlookMessage As Outlook.MailItem
    > > Dim objOutlookRecipient As Outlook.Recipient
    > > Dim objOutlookAttach As Outlook.Attachment

    >
    > [snip]
    >
    > Do you have a reference set to the Microsoft Outlook 12.0 Object Library?
    > You'll need that if you're going to refer to Outlook-defined data types such
    > as the above.
    >
    > As an alternative, you could forego the reference and use late binding by
    > declaring all the Outlook-defined items as Object. You would also have to
    > declare the constants olMailItem, olTo, olCC, and olImportanceHigh yourself,
    > since those are defined by the Outlook object library. But if you don't
    > mind having the reference to the Outlook library, you don't need to do that.
    >
    > --
    > Dirk Goldgar, MS Access MVP
    > Access tips: www.datagnostics.com/tips.html
    >
    > (please reply to the newsgroup)
    >
     
    PsyberFox, May 15, 2010
    #3
  4. PsyberFox

    PsyberFox Guest

    Hi again,

    I have actually resolved the problem by simply using DoCmd.SendObject, so
    not to worry. Thank you in any case!

    Rgds,
    W

    --
    The Psyber Fox
    http://www.psyberconsulting.co.za


    "Dirk Goldgar" wrote:

    > "PsyberFox" <> wrote in message
    > news:...
    > > Hi there,
    > >
    > > I am getting an error stating User-defined type not defined when running
    > > the
    > > following code. I have activated References for Microsoft Office 12.0
    > > Object
    > > Library as well as Microsoft Access 12.0 Object Library. This is in Access
    > > 2007, and off a command button called cmd_Email
    > >
    > > Sub cmd_Email_Click()
    > >
    > > Dim objOutlook As Outlook.Application
    > > Dim objOutlookMessage As Outlook.MailItem
    > > Dim objOutlookRecipient As Outlook.Recipient
    > > Dim objOutlookAttach As Outlook.Attachment

    >
    > [snip]
    >
    > Do you have a reference set to the Microsoft Outlook 12.0 Object Library?
    > You'll need that if you're going to refer to Outlook-defined data types such
    > as the above.
    >
    > As an alternative, you could forego the reference and use late binding by
    > declaring all the Outlook-defined items as Object. You would also have to
    > declare the constants olMailItem, olTo, olCC, and olImportanceHigh yourself,
    > since those are defined by the Outlook object library. But if you don't
    > mind having the reference to the Outlook library, you don't need to do that.
    >
    > --
    > Dirk Goldgar, MS Access MVP
    > Access tips: www.datagnostics.com/tips.html
    >
    > (please reply to the newsgroup)
    >
     
    PsyberFox, May 15, 2010
    #4

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PJ

    Confirming Email addresss and moving to sending email

    PJ, Oct 27, 2003, in forum: Microsoft Access Form Coding
    Replies:
    1
    Views:
    239
    Kevin
    Oct 27, 2003
  2. Guest

    How do I send email to an email address contained in a field

    Guest, Dec 17, 2004, in forum: Microsoft Access Form Coding
    Replies:
    0
    Views:
    199
    Guest
    Dec 17, 2004
  3. Guest

    Selecting Email Contacts Address To Sending Email From Form

    Guest, May 3, 2007, in forum: Microsoft Access Form Coding
    Replies:
    2
    Views:
    236
    Scott McDaniel
    May 3, 2007
  4. Replies:
    1
    Views:
    824
    jahoobob via AccessMonster.com
    Jul 15, 2007
  5. sam

    PLEASE HELP: Send email from Access with data in email body

    sam, Apr 26, 2010, in forum: Microsoft Access Form Coding
    Replies:
    0
    Views:
    267
Loading...

Share This Page