Consulting

Results 1 to 3 of 3

Thread: Access and Outlook Express

  1. #1
    VBAX Newbie
    Joined
    Feb 2005
    Location
    Devon
    Posts
    5
    Location

    Access and Outlook Express

    Hi

    I can send emails with or without attachments from Access using MS Outlook no problem, but I have one user who flatly refuses to install Outlook on his machine (don't ask why - it's beyond me!!!).

    Consequently I've been trying to be able to use Outlook Express instead (which he's quite happy to use!!!!) and found the following freeware code (credit to the author Lyle Fairfield) which uses the msoe.dll

    I've modified the code to suit my needs, but despite several (un)happy hours of trying, can't work out what I'm missing to be able to add an attachment to the email.

    I'd be very grateful if anyone can add the arguments needed to pass to the .dll to enable adding an attachment.

    Thanks............

    Alan

    [vba]

    Option Compare Database
    Option Explicit

    Type MAPIRecip
    Reserved As Long
    RecipClass As Long
    Name As String
    Address As String
    EIDSize As Long
    EntryID As String
    End Type


    Type MAPIFileTag
    Reserved As Long
    TagLength As Long
    Tag() As Byte
    EncodingLength As Long
    Encoding() As Byte
    End Type


    Type MAPIFile
    Reserved As Long
    Flags As Long
    Position As Long
    PathName As String
    FileName As String
    FileType As Long
    End Type


    Type MAPIMessage
    Reserved As Long
    Subject As String
    NoteText As String
    MessageType As String
    DateReceived As String
    ConversationID As String
    Originator As Long
    Flags As Long
    RecipCount As Long
    Recipients As Long
    Files As Long
    FileCount As Long
    End Type


    Declare Function MAPISendMail _
    Lib "c:\program files\outlook express\msoe.dll" ( _
    ByVal Session As Long, _
    ByVal UIParam As Long, _
    message As MAPIMessage, _
    ByVal Flags As Long, _
    ByVal Reserved As Long) As Long


    Sub SendMailWithOE(ByVal strSubject As String, ByVal strMessage As String, _
    ByRef aRecips As Variant)
    Dim recips() As MAPIRecip
    Dim message As MAPIMessage
    Dim z As Long
    ReDim recips(LBound(aRecips) To UBound(aRecips))
    For z = LBound(aRecips) To UBound(aRecips)
    With recips(z)
    .RecipClass = 1
    If InStr(aRecips(z), "@") <> 0 Then
    .Address = StrConv(aRecips(z), vbFromUnicode)
    Else
    .Name = StrConv(aRecips(z), vbFromUnicode)
    End If
    End With
    Next z
    With message
    .NoteText = strMessage
    .Subject = strSubject
    .RecipCount = UBound(recips) - LBound(aRecips) + 1
    .Recipients = VarPtr(recips(LBound(recips)))
    End With

    MAPISendMail 0, 0, message, 0, 0

    End Sub

    Sub TestSendMailwithOE(strSubject As String, strBody As String)

    Dim aRecips(0 To 0) As String

    aRecips(0) = "someone@somewhere.com"

    SendMailWithOE strSubject, strBody, aRecips

    End Sub

    Private Sub cmdEmail_Click()

    Call TestSendMailwithOE("test", "testing message")

    End Sub[/vba]

  2. #2
    I've wrestled with this one for a long time--thanks for posting that code, it finally got me to an answer.

    That code, according to the mvps newsgroup, is buggy--indeed, it crashed Access very nicely for me. The same guy who wrote it posted back to the newsgroup with a bugless version; the thread is here, the updated code is here. Don't know why it never occurred to me to search for an answer to that question. More tips and versions on Tony Toe's excellent site.

    By the way, I would strongly recommend that you check out Michael Kaplan's SimpleMapi objects, which can be dropped right in to VB and VBA, and work pretty nicely (though I have had problems on OE-and-Outlook machines with it). Lots of great stuff there, including an example whose api call looks very much like the OE one, that will show you that by substituting &H8 for the second to last 0 in the call you get to see the message on the screen.

  3. #3
    VBAX Newbie
    Joined
    Feb 2005
    Location
    Devon
    Posts
    5
    Location
    Hi

    Thanks for your very full and complete answer. It's solved a headache for me and works a treat..............

    Again, many thanks

    Alan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •