Autosending Email from VBA

ianclegg

Registered User.
Local time
Today, 22:00
Joined
Jul 14, 2001
Messages
58
Can anyone help?

I have a minor problem when sending emails from vba in an access appliaction.

The code I use is as follows

docmd.sendobj ,,," '" & email address & "' " ,,,msubject,,true

My code sends the email ok, however before sending, Outlook displays the correctly formatted email within the template. I then have to click send to send the email.

Is there a way to just send the email


Regards

Ian clegg
 
Look in VBA help at SendObject and check out what that last argument is doing.
 
Can anyone help?

I have a minor problem when sending emails from vba in an access appliaction.

The code I use is as follows

docmd.sendobj ,,," '" & email address & "' " ,,,msubject,,true

My code sends the email ok, however before sending, Outlook displays the correctly formatted email within the template. I then have to click send to send the email.

Is there a way to just send the email


Regards

Ian clegg

you can send change add .send instead of .display in your code, it will send the email directly.

hereby the example (email with html format + auto send):
Code:
Function sendEmail()
    Dim olApp As Outlook.Application
    Dim objMail As Outlook.MailItem
   Set olApp = Outlook.Application
        Set objMail = olApp.CreateItem(olMailItem)
        With objMail
            'Set body format to HTML
            .To = "tomail"
            .Subject = "subject"
            .BodyFormat = olFormatHTML
            .HTMLBody = "bodyhtml"
            .Send
        End With
set olApp  = nothing
End Function
 
Thanks for the prompt replies

I have tried both methods and have still the same problem.

On setting true to False & using the suggested routine, I get the message

"A program is trying to automatically send email on your behalf. Do you want to do this?

Yes/No Help.

At this point Yes is not available for 5 seconds - giving an even greater delay in sending multiple emails from my form.

Am I missing something


Regards

Ian
 
"A program is trying to automatically send email on your behalf. Do you want to do this?

Yes/No Help.

At this point Yes is not available for 5 seconds - giving an even greater delay in sending multiple emails from my form.

Am I missing something


Regards

Ian
Hi Ian!
This seems to be Microsoft Outlook Error. try to check and debug through your VBA code also the Refreceses in VBA module.
 
Thanks for the prompt replies

I have tried both methods and have still the same problem.

On setting true to False & using the suggested routine, I get the message

"A program is trying to automatically send email on your behalf. Do you want to do this?

Yes/No Help.

At this point Yes is not available for 5 seconds - giving an even greater delay in sending multiple emails from my form.

Am I missing something


Regards

Ian

you can use this code:
Code:
OlSecurityManager.ConnectTo OutlookApp 
OlSecurityManager.DisableOOMWarnings = True 
On Error Goto Finally 
  '... any action with protected objects ... 
Finally: 
  OlSecurityManager.DisableOOMWarnings = False
 

Users who are viewing this thread

Back
Top Bottom