473,566 Members | 2,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access 2003/Outlook 2003 send email from Access

11 New Member
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 "CreateObje ct" failed, "Outlook.Applic ation.CreateIte m(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 4175
nico5038
3,080 Recognized Expert Specialist
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
5554
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 recipient addressees to see the report in the body text window of their email when they open it. I was thinking also about attaching the PDF file to...
1
4139
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 required to answer. A summary of the relevant code is: Dim mailObj as Outlook.MailItem
2
2096
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 every email. Is there a registry setting to change this. Or in outlook or in access ? Thanks Alfred
47
4485
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 company and this is a big decision for us(!) It's not just the money it's committing to an new version of Access!
1
2132
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 "429 ActiveX Componant Can't Create Object" How can I correct this error? Thanks very Much! Kathy Here is the function: ' By Glen Appleton found...
5
2964
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
24363
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
6183
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 using which sends If you want to see the above code in its full context you can see it here: ...
4
3466
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 respective agency record appearing on the main form at the current time. Instead, what I get is the email form without the appropriate information in...
0
7584
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7645
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5485
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.