Results 1 to 4 of 4
  1. #1
    WAVP375 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Dayton Ohio
    Posts
    171

    Problem sending email in VBA

    I am attempting to email an image from a form. The code I am using is as follows. I am getting an error which makes no sense to me at all. Sure could use some help.

    Thanks in advance

    Private Sub BtnEmail_Click()

    'Check for an email address
    If IsNull([EmailAddress]) Then
    MsgBox "Enter Email Address"
    Me.EmailAddress.SetFocus
    Else:
    GoTo Continue
    End If
    Exit Sub

    'Send email
    Continue:
    Dim FileName As String
    Dim FilePath As String
    Dim oOutlook As Outlook.Application
    Dim oEmailItem As MailItem

    FileName = Me.DocumentTitle
    FilePath = Me.ImagePath


    If oOutlook Is Nothing Then
    Set oOutlook = New Outlook.Application
    End If

    Set oEmailItem = oOutlook.CreateItem(olMailItem)
    With oEmailItem
    .To = Me.EmailAddress
    .Subject = "Document from Greene Memorial Archive System"
    .Attachments.Add FilePath
    .Send
    End With

    Set oEmail = Nothing
    Set oOutlook = Nothing

    MsgBox "Email has been sent to " & Me.EmailAddress


    DoCmd.Close acForm, "frmSearch"
    DoCmd.Close
    DoCmd.OpenForm "frmMenu"
    End Sub

    The error message is: User defined Type not defined
    and it highlights the Dim oOutlook as Outlook.Application statement

    I have used this code before without this error

    Any ideas?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    it sounds like you did not reference Outlook app in vbe.
    Open the VBE, (ctl-G)
    menu, tools, references.
    make sure MS Outlook v.XX is checked

  3. #3
    WAVP375 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Dayton Ohio
    Posts
    171
    Thanks ranman that fixed the problem.

  4. #4
    WAVP375 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Dayton Ohio
    Posts
    171
    Another issue! I have done my development on Windows 10 system with Access and outlook level 2016. I am attempting to implement it on a corporate system running Access and Outlook 2010. When I execute the first code I get and error saying 'Can't find Project or library'. The reference list in tools shows a 'Missing Microsoft Outlook 16.0 Object library'. This library does not exist in the reference list and I did not find this object for any other level such as 'Microsoft Outlook 14.0. There must be a way around this?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 12-09-2016, 04:28 PM
  2. Replies: 1
    Last Post: 11-07-2016, 11:18 AM
  3. Replies: 1
    Last Post: 05-05-2013, 12:13 PM
  4. Email sending
    By Steven.Allman in forum Access
    Replies: 25
    Last Post: 06-21-2010, 09:37 AM
  5. Sending email
    By nashr1928 in forum Reports
    Replies: 8
    Last Post: 04-27-2010, 11:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums