G
GJH
I've looked around on how to send emails with multiple attachements from
access. Came across a great set of VB code that sends emails really well,
but when I try to send Attachements all I get is the error message "
Msaccess has caused an error in MSOE.dll. Msaccess will now close." :-( and
not the most helpful message.
I am guessing that the problem is with the MAPIfile.FileType. Some internet
sources say one thing, other say something different, and everything that I
have tried doesn't work, so perhaps there are two problems here ..
Anyhow, it is past midnite here I will check back tomorrow - any thoughts,
hints, farts, or other bright ideas welcome. Not farts - just checking if
you were paying attection
/Gordon - Full Code below
Option Compare Database
Option Explicit
Type MAPIRecipiant
Reserved As Long
RecipClass As Long
Name As String
Address As String
EIDSize As Long
EntryID As String
End Type
'Type MAPIFileTag ' is this really needed??
' 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 MAPIFileTag
FileType As Long ' internet says this should be a string, a long, or
a structure MAPIFileTag
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 TestSendMailWithAttachmentsUsingOE()
Dim MessageOnly As Boolean ' debuging variable. Works when true, bombs
when false!
MessageOnly = True
Dim Recipient(0 To 0) As String
Recipient(0) = "No>[email protected]<Spam" '<Big Grin>
Dim Attachements(0 To 0) As String
Attachements(0) = "C:\autoexec.bak"
Dim Subject As String
Subject = "Email with Attachment"
Dim MessageBody As String
MessageBody = "But I keep getting errors when I try :-("
' Process the email recipients this will go to
Dim Mrecips(0 To 0) As MAPIRecip
With Mrecips(0)
.RecipClass = 1
.Address = StrConv(Recipient(0), vbFromUnicode)
End With
' process the file list for attachments
Dim Mfiles(0 To 0) As MAPIFile
If Not MessageOnly Then
With Mfiles(0)
.Flags = 0
.Reserved = 0
.Position = -1
.PathName = StrConv(Attachements(0), vbFromUnicode)
.FileName = ""
.FileType = 0
End With
End If
Dim MMessage As MAPIMessage
With MMessage
.NoteText = MessageBody
.Subject = Subject
.RecipCount = 1
.Recipients = VarPtr(Mrecips(0))
If Not MessageOnly Then .FileCount = 1
If Not MessageOnly Then .Files = VarPtr(Mfiles(0))
End With
MAPISendMail 0, 0, MMessage, 0, 0
End Sub
access. Came across a great set of VB code that sends emails really well,
but when I try to send Attachements all I get is the error message "
Msaccess has caused an error in MSOE.dll. Msaccess will now close." :-( and
not the most helpful message.
I am guessing that the problem is with the MAPIfile.FileType. Some internet
sources say one thing, other say something different, and everything that I
have tried doesn't work, so perhaps there are two problems here ..
Anyhow, it is past midnite here I will check back tomorrow - any thoughts,
hints, farts, or other bright ideas welcome. Not farts - just checking if
you were paying attection
/Gordon - Full Code below
Option Compare Database
Option Explicit
Type MAPIRecipiant
Reserved As Long
RecipClass As Long
Name As String
Address As String
EIDSize As Long
EntryID As String
End Type
'Type MAPIFileTag ' is this really needed??
' 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 MAPIFileTag
FileType As Long ' internet says this should be a string, a long, or
a structure MAPIFileTag
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 TestSendMailWithAttachmentsUsingOE()
Dim MessageOnly As Boolean ' debuging variable. Works when true, bombs
when false!
MessageOnly = True
Dim Recipient(0 To 0) As String
Recipient(0) = "No>[email protected]<Spam" '<Big Grin>
Dim Attachements(0 To 0) As String
Attachements(0) = "C:\autoexec.bak"
Dim Subject As String
Subject = "Email with Attachment"
Dim MessageBody As String
MessageBody = "But I keep getting errors when I try :-("
' Process the email recipients this will go to
Dim Mrecips(0 To 0) As MAPIRecip
With Mrecips(0)
.RecipClass = 1
.Address = StrConv(Recipient(0), vbFromUnicode)
End With
' process the file list for attachments
Dim Mfiles(0 To 0) As MAPIFile
If Not MessageOnly Then
With Mfiles(0)
.Flags = 0
.Reserved = 0
.Position = -1
.PathName = StrConv(Attachements(0), vbFromUnicode)
.FileName = ""
.FileType = 0
End With
End If
Dim MMessage As MAPIMessage
With MMessage
.NoteText = MessageBody
.Subject = Subject
.RecipCount = 1
.Recipients = VarPtr(Mrecips(0))
If Not MessageOnly Then .FileCount = 1
If Not MessageOnly Then .Files = VarPtr(Mfiles(0))
End With
MAPISendMail 0, 0, MMessage, 0, 0
End Sub