Link to home
Start Free TrialLog in
Avatar of pmurray928
pmurray928

asked on

Avoiding "Choose Profile" box with Access' Sendobject

This is from several years ago, and I have a follow-up question:
--------------------------------------------------
Hi,
i have a sub that uses SendObject action to mail me a message.  It works ok but how do i get it to not pop up the "Choose Profile" window, is this some option in IE (outlook) or is it part of MAPI. what ever the case how can i get it to not popup like that. Any help would be great.  

View Accepted Answer

 
Question History
Accepted Answer from ramrom  03/14/1998 06:48PM PST  
A long answer: use the following subroutine in lieu of SendObject. It creates a MAPI session and a MAPI message.
The combination of:
MapiSession.Logon profilename:="MS Exchange Settings"
and
.Send showdialog:=false
suppress the window.
Code commented out adds stuff to the message. The active code is what it takes to send a simple text message to 1 recipient.

Sub SendMAPIMessage()
 Dim MapiSession As Object
 Dim MapiMessage As Object
 Dim MapiRecipient As Object
 Dim MapiAttachment As Object
 Dim Recpt, errObj As Long, errMsg
 On Error GoTo MAPITrap        ' Create the MAPI Session.
 Set MapiSession = CreateObject("Mapi.Session")
 ' Log on to the session
 MapiSession.Logon profilename:="MS Exchange Settings"
 ' Add a message to the Outbox.
 Set MapiMessage = MapiSession.Outbox.Messages.Add
 ' Add the recipients of the message. Note, each recipient must be
 ' added separately to the Recipients collection of the Message
 ' object.
 With MapiMessage
   Set MapiRecipient = MapiMessage.Recipients.Add
   MapiRecipient.Name = "ramrom@earthling.net"
   MapiRecipient.type = mapiTo
   'Set MapiRecipient = MapiMessage.Recipients.Add
   'MapiRecipient.Name = "Andrew Fuller"
   'MapiRecipient.type = mapiCc
   'Set MapiRecipient = MapiMessage.Recipients.Add
   'MapiRecipient.Name = "Michael Suyama"
   'MapiRecipient.type = mapiBcc
   ' Resolve each recipient's e-mail name.
   For Recpt = 0 To .Recipients.Count - 1
     .Recipients(Recpt).Resolve showdialog:=True
   Next
   ' Attach a file to the message.
   'Set MapiAttachment = MapiMessage.Attachments.Add
   'With MapiAttachment
   '  .Name = "Customers.txt"
   '  .type = mapiFileData
   '  .Source = "C:\Examples\Customers.txt"
   '  .ReadFromFile FileName:="C:\Examples\Customers.txt"
   '  .position = 2880
   'End With
   ' Assign the text, subject, and importance of the message.
   .subject = "My Subject"
   .Text = "This is the text of my message." & vbCrLf & vbCrLf
   .importance = mapiHigh
   ' View the message in Microsoft Exchange before sending. Set
   ' the ShowDialog argument to False if you want to send the
   ' message without viewing it in Microsoft Exchange.
   .Send showdialog:=False
 End With
 Set MapiSession = Nothing  ' Clear the object variable.

MAPIExit:
 Exit Sub

MAPITrap:
 errObj = Err - vbObjectError  ' Strip out the OLE automation error.
 Select Case errObj
  Case 275                  ' User cancelled sending of message.
   Resume MAPIExit
  Case Else
   errMsg = MsgBox("Error " & errObj & " was returned.")
   Resume MAPIExit
 End Select
End Sub

-------------------------------------------------------

The question: This works for me as is, but how do I insert an attachment in the email.

Thanks for any help.


ASKER CERTIFIED SOLUTION
Avatar of shanesuebsahakarn
shanesuebsahakarn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 1William
1William

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept question, points to shanesuebsahakarn
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
1William
EE Cleanup Volunteer