473,401 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Access 2003/Outlook 2003 send email from Access

11
I have problem with the following code when OUTLOOK.EXE process in on.
First, I make sure no outlook is running. The "GetObject" will set the oOApp to outlook and the code works fine. One problem is that if I comment out the ".Display" the "Quit" will not stop the outlook process.
Second, if the outlook process is on, the "GetObject" and "CreateObject" failed, "Outlook.Application.CreateItem(olMailItem)" also failed.
I don't know why "GetObject" won't detect that outlook is on.
Does anyone know why?


Expand|Select|Wrap|Line Numbers
  1. Public Sub SendMail(strMailAddr As String, strNote As String)
  2. On Error GoTo ErrorHandler
  3.  
  4.     Dim oOApp As Outlook.Application
  5.     Dim oOMail As Outlook.MailItem
  6.     Dim bStart As Boolean
  7.  
  8.  
  9.     bStart = False
  10.     Set oOApp = GetObject("", "Outlook.Application")
  11.     If oOApp Is Nothing Then
  12.         Set oOApp = CreateObject("Outlook.Application")
  13.     End If
  14.     If oOApp Is Nothing Then
  15.         Set oOMail = Outlook.Application.CreateItem(olMailItem)
  16.     Else
  17.         bStart = True
  18.         Set oOMail = oOApp.CreateItem(olMailItem)
  19.     End If
  20.     If Not oOMail Is Nothing Then
  21.         With oOMail
  22.            .Subject = "NABP Call Message"
  23.            .To = strMailAddr
  24.            .body = strNote
  25.            .Importance = olImportanceHigh
  26.            .Display
  27.            .Send
  28.         End With
  29.         If bStart Then
  30.             oOApp.Quit
  31.         End If
  32.     Else
  33.         MsgBox "Email sending is unsuccessful."
  34.     End If
  35.  
  36. Exit_ErrorHandler:
  37.     ' clean up
  38.     Set oOApp = Nothing
  39.     Set oOMail = Nothing
  40.  
  41.     Exit Sub
  42.  
  43. ErrorHandler:
  44.     ' Display error information.
  45.     MsgBox "(" & Err.Number & ") " & Err.Description
  46.     Resume Next
  47.  
  48. End Sub
Oct 12 '07 #1
1 4166
nico5038
3,080 Expert 2GB
I see you're using "Late binding", perhaps switching to early binding works better.
Check:
http://www.dicks-clicks.com/excel/olBinding.htm

Nic;o)
Oct 12 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: MLH | last post by:
I print to a device that creates a PDF. Knowing the filename, how can I then embed the PDF into the body text of an OutLook Express outbound email & send to a specified address in a table? I want...
1
by: Devonish | last post by:
I am composing an email with Access VB and then sending it from within Access. Everything works correctly (the email actually goes!) but Outlook ask some irritating questions that the user is...
2
by: A | last post by:
I am sending email via access. Outlook now blocks me with following message: A program is trying to automatically send e-mail on your behalf. Do you want to allow this. I must click yes for...
47
by: ship | last post by:
Hi We need some advice: We are thinking of upgrading our Access database from Access 2000 to Access 2004. How stable is MS Office 2003? (particularly Access 2003). We are just a small...
1
by: kathyk | last post by:
Hi, I created an application in MS Access 2000. Since upgrading to MS Access 2003 I have been finding all sorts of strange things. My current problem is with the function below. Ig get an error...
5
by: horsetransport | last post by:
Hello, Below is what I "Know how to do" but it doesn't accomplish what I want I have table called sndmail fields that matter useremail and mailsent
10
by: Mike Charney | last post by:
Is there a simple way to send SMTP email from Access VBA? Mike m charney at dunlap hospital dot org
16
by: Kosmos | last post by:
Good afternoon everyone, just wondering if anyone knew if it's possible to send meetings or appointments through email when you run VBA or SQL code in Access 2003? The following is the code I've been...
4
by: zufie | last post by:
I have a main form containing a command SEND button that prompts an email form to pop up. The email address(es) that are supposed to appear on the email form are those corresponding to the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.