• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

Avoiding "Choose Profile" box with Access' Sendobject

This is from several years ago, and I have a follow-up question:
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"
.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
   ' 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.

 Exit Sub

 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.

1 Solution
It's an option in Outlook. Open Control Panel, and go to Mail. If you are using Outlook 2000 or later, click on the "Show Profiles" option. You should then see a screen with "Prompt for Profile" or "Always use this Profile".

To remove the prompt, select the second option, and choose your profile. Be careful if you have multiple e-mail profiles set up.
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.
EE Cleanup Volunteer

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Tackle projects and never again get stuck behind a technical roadblock.
Join Now