DoCmd.SendObject

R

Ron Hinds

The behavior of the DoCmd.SendObject method seems to be arbitrary in regards
to which eMail client it selects to do the sending. Sometimes it selects
Outlook Express, sometimes it selects Outlook. We only use the scheduling
functions of Outlook through our Access app. No one here uses Outlook for
eMail - we all use Outlook Express. I don't see any way in the SendObject
method to specify which eMail client I want to use. Is anyone aware of a way
I can force it to always select Outlook Express?
 
P

Pieter Wijnen

Not strictly an Access Problem but,
Both Outlook & Express wants to be your default mail handler
make sure not to select "make me your default mail handler"
The option can be turned off through GrpEdit.msc I think (Computer & Domain)

HTH

Pieter
 
D

Dirk Goldgar

In
Ron Hinds said:
The behavior of the DoCmd.SendObject method seems to be arbitrary in
regards to which eMail client it selects to do the sending. Sometimes
it selects Outlook Express, sometimes it selects Outlook. We only use
the scheduling functions of Outlook through our Access app. No one
here uses Outlook for eMail - we all use Outlook Express. I don't see
any way in the SendObject method to specify which eMail client I want
to use. Is anyone aware of a way I can force it to always select
Outlook Express?

I believe SendObject will always use your default mail client. The
problem is that Outlook likes to make itself the default mail client
when you run it. I don't think it'll do that without requesting some
sort of confirmation, but I wouldn't count on it.

It is possible to use MAPI to explictly send mail using Outlook Express.
For example, the following module provides a function very similar to
SendObject, except that it doesn't have the built-in feature to attach
an Access object.

'----- start of module code -----
Option Compare Database
Option Explicit

' Code adapted from a number of sources, especially
' including Lyle Fairfield, and modified by Dirk Goldgar.

Private Type MapiRecip
Reserved As Long
RecipClass As Long
Name As String
Address As String
EIDSize As Long
EntryID As Long
End Type

Private Type MAPIFileDesc
Reserved As Long
flags As Long
Position As Long
PathName As String
FileName As String
FileType As Long
End Type

Private 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
FileCount As Long
Files As Long
End Type

Private 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

Public Function SendMailWithOE( _
ByVal pstrSubject As String, _
ByVal pstrMessage As String, _
Optional ByRef pstrRecipientsTo As String, _
Optional ByRef pstrRecipientsCC As String, _
Optional ByRef pstrRecipientsBCC As String, _
Optional ByVal pstrFiles As String, _
Optional ByVal pblnDisplayMessage As Boolean = True) _
As Long

On Error GoTo Err_Handler

Dim aFiles() As String
Dim aRecips() As String

Dim FilePaths() As MAPIFileDesc
Dim Recips() As MapiRecip
Dim Message As MAPIMessage
Dim lngFlags As Long

Dim lngRC As Long
Dim z As Long

Dim iLastRecip As Integer

If pstrFiles <> vbNullString Then
aFiles = Split(pstrFiles, ",")
ReDim FilePaths(LBound(aFiles) To UBound(aFiles))
For z = LBound(aFiles) To UBound(aFiles)
With FilePaths(z)
.Position = -1
.PathName = StrConv(aFiles(z), vbFromUnicode)
End With
Next z
Message.FileCount = UBound(FilePaths) - LBound(FilePaths) + 1
Message.Files = VarPtr(FilePaths(LBound(FilePaths)))
Else
Message.FileCount = 0
End If

iLastRecip = -1

If Len(pstrRecipientsTo) > 0 Then
Erase aRecips
aRecips = Split(pstrRecipientsTo, ",")
ReDim Preserve Recips(0 To (iLastRecip + 1 + UBound(aRecips)))
For z = LBound(aRecips) To UBound(aRecips)
iLastRecip = iLastRecip + 1
With Recips(iLastRecip)
.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
End If

If Len(pstrRecipientsCC) > 0 Then
Erase aRecips
aRecips = Split(pstrRecipientsCC, ",")
ReDim Preserve Recips(0 To (iLastRecip + 1 + UBound(aRecips)))
For z = LBound(aRecips) To UBound(aRecips)
iLastRecip = iLastRecip + 1
With Recips(iLastRecip)
.RecipClass = 2
If InStr(aRecips(z), "@") <> 0 Then
.Address = StrConv(aRecips(z), vbFromUnicode)
Else
.Name = StrConv(aRecips(z), vbFromUnicode)
End If
End With
Next z
End If

If Len(pstrRecipientsBCC) > 0 Then
Erase aRecips
aRecips = Split(pstrRecipientsBCC, ",")
ReDim Preserve Recips(0 To (iLastRecip + 1 + UBound(aRecips)))
For z = LBound(aRecips) To UBound(aRecips)
iLastRecip = iLastRecip + 1
With Recips(iLastRecip)
.RecipClass = 2
If InStr(aRecips(z), "@") <> 0 Then
.Address = StrConv(aRecips(z), vbFromUnicode)
Else
.Name = StrConv(aRecips(z), vbFromUnicode)
End If
End With
Next z
End If

With Message
.NoteText = pstrMessage
.RecipCount = UBound(Recips) - LBound(Recips) + 1
.Recipients = VarPtr(Recips(LBound(Recips)))
.Subject = pstrSubject
End With

If pblnDisplayMessage = True Then
lngFlags = MAPI_DIALOG
Else
lngFlags = 0
End If

SendMailWithOE = MAPISendMail(0, 0, Message, lngFlags, 0)

Exit_Point:
Exit Function

Err_Handler:
subDisplayAndLogError "SendMailWithOE", Err.Number, Err.Description
Resume Exit_Point

End Function
'----- end of module code -----
 
R

Ron Hinds

Sweeet! I assume pblnDisplayMessage brings up the UI? That's part of the
functionality I'm looking for...

Thanks!
 
D

Dirk Goldgar

In
Ron Hinds said:
Sweeet! I assume pblnDisplayMessage brings up the UI? That's part of
the functionality I'm looking for...

Yes, that's right. As posted, it defaults to True, which means that the
message is displayed for the user to edit, after which the user can send
or cancel it.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top