URGENT HELP! DoCmd.SendObject does not work automatically when Outlook not open

C

Christine

Preface: This is a repeat of a msg just sent, but it isn't
appearing in the Posts list...sorry if it is indeed a
duplicate.

My app is supposed to automatically send email (with a
report attached) to people specified in the code after a
form's command button's On Click event. Sending the email
must be completely transparent to the user so they cannot
cancel the email, edit it, etc. The code is

DoCmd.SendObject acSendNoObject, , , strMgrAddress, , ,
mTitle, mMsg, False

After some tests using different PCs (the app will be used
throughout the company) we're seeing different results on
different systems:

1. If the user doesn't have Outlook open...
....the user gets a message "Choose Profile". Outlook is
displayed in the Profile Name Box. Clicking the
Option "Set as Default Profile" in this message box
doesn't do anything. It also doesn't matter if the default
profile is set to Outlook from within Outlook.

2. If Outlook is open...
....one of two things can happen: a pop-up "Choose Profile"
message appears OR a popup for the Internet Connection
Wizard appears.

3. Sometimes Outlook's security warning appears ("Another
application is trying to send email..."), and sometimes it
doesn't!! I've heard that this message is automatic in
Outlook and can be turned off by our system administrator,
but he hasn't turned anything off, so why the message
appears intermittantly is baffeling. When the message does
appear, however,... we'll we don't want it to, since the
user could potentially cancel the email.

4. If the user is using a laptop or if the PC is
configured so the user has an option for connecting...
....a Microsoft Exchange Server prompt asks them if they
want to connect to internet or work off-line. If they
choose to work off-line, then the email can't be sent! I
suppose we can't force them to connect, but then there
must be some sort of tracking to show that the email
wasn't sent.

We are using Access 2002 SP-2. Some systems have XP,
others have Windows 2000. All have Outlook 2002 SP-2.

I have seen some code that has "Dim objOutlook As
Outlook.Application", but wonder what this does that
SendObject does not. Could "Dim objOutlook As
Outlook.Application" solve some of these problems? And, if
so, could someone provide the code, as I can't seem to
find it again and anyway, when I first saw it, the code
was actually doing a heck of alot more than I need.

I'm in urgent need to resolve this quickly. Can someone
PLEASE spare a bit of time to help?

Grateful forever to any and all,
Christine
 
J

Jamie Richards

Hi Christine

I have included some of the code below that you asked about The Dim
objOutlook As Outlook.Application you mentioned is merely the code that
creates the instance of the Outlook application so you can use it. Have you
set a refernce to the Outlook object library? Someone will no doubt be able
to answer your question in detail, but I don't think you can get around the
Outlook email warning, at least not without the assistance of the
administrator.

I did not write this code, but acquired it from somewhere off the net. So I
can't credit the author. Hopefull you will find it useful.


' Outlook Automation
Dim olApp As Outlook.Application
'Logon.Doesn 't hurt if you are already running and logged on...
Dim olNs As Outlook.NameSpace
'Place code above the line into the Declarations section of your module
'********************************************
Public Sub SendMail(strMailTo As String, strMailSubject As String, _
strMailBody As String, Optional strMailCc As String, Optional strBcc
As String)
' Send a message to your new contact.
Dim olMail As Outlook.MailItem
Set olApp = CreateObject("Outlook.Application")
Set olMail = olApp.CreateItem(olMailItem)
' Fill out & send message...
olMail.To = strMailTo
olMail.Subject = strMailSubject
olMail.Body = strMailBody
olMail.Cc = strMailCc
olMail.Bcc = strBcc
'Send
olMail.Send

' Clean up...
Set olMail = Nothing
olNs.Logoff
Set olNs = Nothing
Set olApp = Nothing

End Sub


Jamie

Server side anti spam rules are enforced and ALL unsolicited email is
deleted.
 
C

Christine

Thanks for that, Jamie. I tried it out and it messed up
other bits of the form. - errors saying "user defined type
not defined" on the events for OnActivate and OnCurrent.
However, this might because the code you provided says

"Public Sub SendMail(strMailTo As String, strMailSubject
As String, strMailBody As String, Optional strMailCc As
String, Optional strBcc As String)",

which definately conflicts with the command button that
calls the code, i.e. "Private Sub cmdSubmit_Click()". It's
when the user clicks "Submit" that the email should be
sent. I'm not certain how to merge your recommended
command (Public Sub SendEmail) with my "Private Sub
cmbSubmit" code.

Also, I checked the references and Microsoft Outlook 10.0
Object Libary is checked.

Hoping you and others can respond soon!
Christine
 
A

AlCamp

Christine,
One more quick suggestion. Have you tried de-installing Outlook and
re-installing it? Maybe as a last resort...?
That might give Windows the kick in the head it needs to realize that
Outlook is your default email app.
hth
Al Camp
 
J

Jamie Richards

Hi Chris,

Sorry for not clarifying. I was of the view that you'd stick that code into
a standard module and call the SendMail function (passing the required
arguments) from the click event of the button on your form. Unforunately I
do not have Outlook installed on my home machine and cannot test it, but I
have used that procedure in work environment very similar to what you have
described. I also had the issue of the Outlook security warning, but then I
wasn't trying to hide the email from the users. Sorry I couldn't help
more. Good luck.

Jamie


Server side anti spam rules are enforced and ALL unsolicited email is
deleted.
 
C

Christine

Hi, Al - thanks for checking up on me! I'm getting so
frustrated!

I only have the one version (2002) and have never had any
other. So, guess that's one lead we can't follow up!

Our MIS department HATES having to reinstall stuff,
especially when it otherwise works as it should.

Whilst waiting for replys here, I found a site that has
very similar code as what Jamie provided. It works, but it
is SO similar I don't understand why one works and the
other doesn't. The only difference (and it may be a big
one) is that, in addition to setting the reference to
Outlook, you also have to ref Microsoft Scripting Runtime,
which was unchecked before.

Here's the code, which is in a module and called via a
macro:
---------------------
Public Function SendEMail()

Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim SubjectLine As String
Dim fso As FileSystemObject
Dim MyBodyText As String

Set fso = New FileSystemObject

Set MyOutlook = New Outlook.Application

Set MyMail = MyOutlook.CreateItem(olMailItem)

' MyMail.To = MailList("email")

MyMail.Subject = SubjectLine
MyMail.Body = MyBodyText

MyMail.Send

Set MyOutlook = Nothing

End Function
 
J

Jamie Richards

Hi Christine,

Sorry you haven't had any joy yet. The code you posted that has the
scripting run time refererence isn't actually using it! At least not in
that code youposted. It is creating an instance of a file system object but
that is all. There is no need to do that in order for the rest of that code
to work. All it's doing is using a portion of your resources which it has
assigned to the creation of the fso. Worse than that, after creating the
fso, it doesn't destroy it (by setting it to nothing). I can't see any
benefit in using it, sorry. I hope you get a solution soon.

Jamie

Server side anti spam rules are enforced and ALL unsolicited email is
deleted.
 
J

Jamie Richards

Christine,

In case you re-visit this post, "Jeff" has posted a workaround for this issue in this NG under the subject "
** Found needed SOLUTION **"

Jamie
 

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