Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DoCmd.SendObject

4 views
Skip to first unread message

Ron Hinds

unread,
Aug 29, 2007, 1:49:06 PM8/29/07
to
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?


Pieter Wijnen

unread,
Aug 29, 2007, 2:11:59 PM8/29/07
to
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

"Ron Hinds" <bi...@microsoft.com> wrote in message
news:OPc8kTm6...@TK2MSFTNGP02.phx.gbl...

Dirk Goldgar

unread,
Aug 29, 2007, 2:16:32 PM8/29/07
to
In news:OPc8kTm6...@TK2MSFTNGP02.phx.gbl,

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 -----

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Ron Hinds

unread,
Aug 29, 2007, 4:41:20 PM8/29/07
to
Sweeet! I assume pblnDisplayMessage brings up the UI? That's part of the
functionality I'm looking for...

Thanks!

"Dirk Goldgar" <d...@NOdataSPAMgnostics.com> wrote in message
news:ujyk1im6...@TK2MSFTNGP03.phx.gbl...

Dirk Goldgar

unread,
Aug 30, 2007, 12:47:55 AM8/30/07
to
In news:%231wf1zn...@TK2MSFTNGP05.phx.gbl,

Ron Hinds <bi...@microsoft.com> wrote:
> 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.

0 new messages