Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending Mail without opening Outlook 3

Status
Not open for further replies.

rgbanse

MIS
Jun 4, 2001
211
0
0
US
From The Land Of The Awful Shadow
Using DoCmd.SendObject I want to to be able to send reports without having Outlook open. Is there a way to send mail without actually opening Outlook. Kinda like when you have it closed and it asks which account you want to use.
Thx in advance,
RGB
 
Consider this....it work in NT for me via an Excel file....there's alot of variable stuff and file opens left out.....here's just the email section:

Sub auto_open()
Dim ol As Outlook.Application
Dim ns As NameSpace
Dim folder As MAPIFolder
Dim newMessage As MailItem
Dim exp As Explorer

Application.DisplayAlerts = False
Application.ScreenUpdating = False

'---------------email section ------------

Set ol = CreateObject("Outlook.Application")
Set ns = ol.GetNamespace("MAPI")

On Error GoTo MLholycow
ns.Logon "Microsoft Outlook Internet Settings"
GoTo MLwhew

MLholycow:

Set ol = Nothing
Set ns = Nothing
Set ol = CreateObject("Outlook.Application")
Set ns = ol.GetNamespace("MAPI")
myUser = ns.CurrentUser.Name

MLwhew:

nl = Chr(10)
myBody = "Multi-Layer Ship Log for " & rundate

Set newMessage = ol.CreateItem(olMailItem)

With newMessage

.Subject = "Multi-Layer Ship Log " & rundate & " Exception report also"

.Body = myBody
.Recipients.Add("drat@mediaone.net").Type = olTo
.Recipients.Add("joesmoe@mediaone.net").Type = olCC
.Attachments.Add mypath & filebody & formattedrundate, olByValue, 2
.Send
End With

Set folder = ns.GetDefaultFolder(olFolderOutbox)
Set exp = ol.ActiveExplorer

If exp Is Nothing Then
Set exp = folder.GetExplorer(olFolderDisplayNoNavigation)
Do Until folder.Items.Count = 0
exp.Display
Loop
exp.Close
End If
ns.Logoff

Set ol = Nothing

end sub




If I'm way off let me know:
drat@mediaone.net
 
Check the FAQ section in the VB 5&6 forum.
 
Thx drat and dsi
both helped a bunch a star for each
thx
RGB
 
Hello Guys,

In my case, this VBA would not work and OutLook is
requesting for "transport provider".
Would you have any clue to this situation ?
In case of normal use of Outlook97 I never get the problem
like this.

LarryJR
 
I believe the "transport provider" error would be related to the Mapi.

Although not sure.

You are using Internet Explorer correct?

 
TO: Ratman

>You are using Internet Explorer correct?

Yes, I am using Ie5.5 SP2 in Win95 and Tool-internet
option- program TAB - e-mail is set to Microsoft Outlook,
I am sure this is the normanl condition to use the
OutLook97 with Ie5.5.
Woul you find any not normal with this condition ?


 
The code I submitted works on NT or '98SE with Outlook '98.
I never ran it with Outlook '97
 
TO: Ratman
Thank you for above,
For the first time I ran your code changing the definitions
of variables as all like Dim ol,ns,..... ,declaring them as
grobal objects and got the problem, for I didn't set the
reference to OutLook object library believing that it is
not necessary when
Set ol = CreateObject("Outlook.Application")
is executed.
After I SET THE REFERENCE TO OUTLOOK OBJECT LIBRARY
it worked correctly as it is !!(Urah ) .

But I still feel that the reference to OutLook object
library is not necessary in this code.

In your case with Outlook98 in NT, is the reference
to OUTLOOK Library set correct ?

Could your try my case declaring variables like as
Dim ol,ns,folder,newMessage,exp
without setting the reference to Outlook object library ?
If you will succeed, this problem is peculiar to OL97
I wonder.

LarryJR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top