By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,493 Members | 1,351 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,493 IT Pros & Developers. It's quick & easy.

Access 2003/Outlook 2003 send email from Access

P: 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
Share this Question
Share on Google+
1 Reply


nico5038
Expert 2.5K+
P: 3,072
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

Post your reply

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