A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Create email from Access on Outlook and make sure that email has beensent using WithEvents method



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old April 14th 09, 12:40 PM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 1
Default Create email from Access on Outlook and make sure that email has beensent using WithEvents method

Hi,
I'm trying to send an email confirmation from Access using VBA. I then
want to make sure that the email has been sent (ie user didn't close
the email window without sending the email). In order to achieve that,
I'm using the WithEvent method in a class module.
I use Office 2003, with Word as the email editor of Outlook. Not being
a specialist, I don't understand why my program fail to catch events
from Outlook. Bellow you will find the code I'm using, please let me
know if you can help:

All code is located in the my Access Project:
In the Class Module names "clsEmailConfo", I have the following code:

Option Compare Database
Option Explicit

Public WithEvents objOutlook As Outlook.Application
Public WithEvents objOutlookMsg As Outlook.MailItem



Private Sub Class_Initialize()

Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)


End Sub


Sub sendEmailConfo(Optional myTo As String, Optional myBcc As String,
Optional myCC As String, Optional mySubject As String, Optional myBody
As String)
With objOutlookMsg
.To = myTo
.CC = myCC
.BCC = myBcc
'.Attachments.Add (mypathname)
.Subject = "test"

.BodyFormat = olFormatHTML

.HTMLBody = myBody



.Display

End With
End Sub


Private Sub objOutlook_ItemSend(ByVal Item As Object, Cancel As
Boolean)

MsgBox ("TEST")

End Sub

Private Sub objOutlookMsg_Send(Cancel As Boolean)
MsgBox ("TEST")
End Sub


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

In a module, I have the follwoing code:

Sub test()
Dim myEmail As clsEmailConfo
Set myEmail = New clsEmailConfo

myEmail.sendEmailConfo ", , , "test", "test"


End Sub


Any help would be greatly apreciated
Ads
  #2  
Old April 14th 09, 02:37 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Create email from Access on Outlook and make sure that email has been sent using WithEvents method

Your class reference in the code module is out of scope as soon as Sub
test() ends. Declare your Dim myEmail As clsEmailConfo at the module level
so the class reference stays alive.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


wrote in message
...
Hi,
I'm trying to send an email confirmation from Access using VBA. I then
want to make sure that the email has been sent (ie user didn't close
the email window without sending the email). In order to achieve that,
I'm using the WithEvent method in a class module.
I use Office 2003, with Word as the email editor of Outlook. Not being
a specialist, I don't understand why my program fail to catch events
from Outlook. Bellow you will find the code I'm using, please let me
know if you can help:

All code is located in the my Access Project:
In the Class Module names "clsEmailConfo", I have the following code:

Option Compare Database
Option Explicit

Public WithEvents objOutlook As Outlook.Application
Public WithEvents objOutlookMsg As Outlook.MailItem



Private Sub Class_Initialize()

Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)


End Sub


Sub sendEmailConfo(Optional myTo As String, Optional myBcc As String,
Optional myCC As String, Optional mySubject As String, Optional myBody
As String)
With objOutlookMsg
.To = myTo
.CC = myCC
.BCC = myBcc
'.Attachments.Add (mypathname)
.Subject = "test"

.BodyFormat = olFormatHTML

.HTMLBody = myBody



.Display

End With
End Sub


Private Sub objOutlook_ItemSend(ByVal Item As Object, Cancel As
Boolean)

MsgBox ("TEST")

End Sub

Private Sub objOutlookMsg_Send(Cancel As Boolean)
MsgBox ("TEST")
End Sub


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

In a module, I have the follwoing code:

Sub test()
Dim myEmail As clsEmailConfo
Set myEmail = New clsEmailConfo

myEmail.sendEmailConfo ", , , "test", "test"


End Sub


Any help would be greatly apreciated


  #3  
Old April 14th 09, 03:28 PM posted to microsoft.public.outlook.program_vba
nono[_2_]
external usenet poster
 
Posts: 2
Default Create email from Access on Outlook and make sure that email h

Ken,
Thank you very much for your help on that matter, Looks like it will be
working now.
greatly apreciated.
Arnaud

  #4  
Old April 14th 09, 06:53 PM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default Create email from Access on Outlook and make sure that email has been sent using WithEvents method



Damn, I should get used to reading the newsgroups buttom up in order to see
which double posting has been answered yet...


--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: http://www.vboffice.net/product.html?pub=6&lang=en


Am Tue, 14 Apr 2009 09:37:26 -0400 schrieb Ken Slovak - [MVP - Outlook]:

Your class reference in the code module is out of scope as soon as Sub
test() ends. Declare your Dim myEmail As clsEmailConfo at the module level
so the class reference stays alive.

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I create a task from selected email, then move email to arc GabrielDubic Outlook and VBA 0 August 18th 08 09:09 AM
2 simple macros - create task from email and move email to folder [email protected] Outlook and VBA 5 February 4th 07 09:57 AM
Have all email addresses in one email using Outlook called from Access 03 Ultraviolet47 Outlook - General Queries 0 November 17th 06 06:45 PM
can't make outlook express default email app when send page by email merdrum Outlook Express 3 January 16th 06 02:28 AM
Hotmail no longer allows email access via Outlook Express for free email accounts? Christina Outlook Express 3 January 11th 06 04:49 AM


All times are GMT +1. The time now is 04:07 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2024 Outlook Banter.
The comments are property of their posters.