Results 1 to 4 of 4
  1. #1
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496

    send outlook email with late binding

    sorry, it may be late (or I may be showing my naiveté..) but could I kindly ask some one to proof this; I'm getting the error:
    olMail not defined...
    (stumped)

    Public Sub SendEmail(varAddress As Variant, varSubject As String, varBody As String)
    Dim CurrFile As String
    Dim olApp As Object
    Dim olNameSpace As Object
    Dim olMail As Object
    Set olApp = GetObject("Outlook.Application")
    If Err.Number0 Then
    Err.Clear
    Set olApp = CreateObject("Outlook.Application")
    If Err.Number0 Then
    MsgBox "Cannot get Outlook"
    Exit Sub
    End If
    End If
    Set olApp = CreateObject("Outlook.Application")
    olApp.GetNamespace("MAPI").Logon
    Set olMail = olApp.CreateItem(0)
    Dim vTitle As String
    Dim vPrompt As String
    Dim responce As Variant
    If IsNull(varAddress) Then
    vTitle = "MISSING ADDRESS"
    vPrompt = "Address is incorrect or missing; no email will be sent"
    responce = MsgBox(vPrompt, vbOKOnly + vbCritical, vTitle)
    Exit Sub
    Else
    With olMail
    .To = varAddress & ""
    .Subject = Nz(varSubject, "")


    .Body = Nz(varBody, "")
    .Display
    End With
    End If
    Set olMail = Nothing
    CleanUp
    End Sub

    many thanks in advance
    mark

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Looks like late binding to me.

    Why are you including
    olApp.GetNamespace("MAPI").Logon

    I don't see it being used and I suppose it could be conflicting with trying to set the mail object.

  3. #3
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    I tried commenting the MAPI line, and it had no effect what so ever (and I agree, I don't see that it is used, it's just part of a snippet of code I copied, and never took the time to learn about... so I've always left it there; I promise, after I solve the current dilemma, I'll take the time to learn about Namespace and "MAPI"...)

    the odd thing is that this morning. the error is at the line
    Set olMail = olApp.CreateIteem(0)
    " the variable olApp not defined "

    still stumped,
    Mark

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Maybe build a new form or at least a new control? I was able to get the following to work. With reference to Outlook Object and without, with Outlook Running and without.

    Code:
    Dim olApp As Object
    Dim objMail As Object
    Set olApp = CreateObject("Outlook.Application") 'Create a new instance of Outlook
    'Create e-mail item
    'Set objMail = olApp.CreateItem(olMailItem)
    Set objMail = olApp.CreateItem(0)
    With objMail
    'Set body format to HTML
    '.BodyFormat = olFormatHTML
    .bodyformat = 2
    .To = "Email@Domain.com"
    .Subject = "Subject"
    .HTMLBody = "Text "
    .Save
    .send
    End With

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

Similar Threads

  1. Replies: 9
    Last Post: 11-27-2013, 11:08 AM
  2. Replies: 5
    Last Post: 04-25-2013, 10:36 AM
  3. How do I achieve late binding on a Chart?
    By RocketMonkey in forum Forms
    Replies: 1
    Last Post: 02-12-2013, 02:11 PM
  4. Send email in Outlook with attachment
    By kelkan in forum Programming
    Replies: 1
    Last Post: 02-01-2013, 10:31 PM
  5. Send email from Access thru Outlook
    By ZMAN in forum Forms
    Replies: 2
    Last Post: 11-27-2010, 06:10 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