Outlook not created

G

Guest

I am trying to send an email with attachment from Access 2007. The following
code fails to detect Outlook even though it is open, or even try to create a
new instance.

Dim objApp As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecipient As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim blnOutlookInitiallyOpen As Boolean
Dim strProcName As String

On Error Resume Next
strProcName = "SendOutlookMessage"

blnOutlookInitiallyOpen = True

Set objApp = GetObject(, "Outlook.Application")
If objApp Is Nothing Then
Set objApp = CreateObject("Outlook.Application")
'* Outlook wasn't open when this function started.
blnOutlookInitiallyOpen = False
End If
If Err <> 0 Then Beep: _
MsgBox "Error in " & strProcName & " (1): " _
& Err.Number & " - " & Err.Description: _
Err.Clear: _
GoTo Exit_Section

The error is: Error in SendOutlookMessage(1): 429 - ActiveX component can't
create object.

I have set a reference to Microsoft Outlook 12 Object Library and tried with
both Outlook open and closed before running it. I also moved it onto an
Access 2000 machine and had the same error.

Can anyone see a problem?
 
J

John Nurick

Hi Neville,

A quick look through the code doesn't show any obvious problems. Maybe
you'll do better to ask in an Outlook forum.
 
S

Stuart McCall

NevilleT said:
I am trying to send an email with attachment from Access 2007. The
following
code fails to detect Outlook even though it is open, or even try to create
a
new instance.

Dim objApp As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecipient As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim blnOutlookInitiallyOpen As Boolean
Dim strProcName As String

On Error Resume Next
strProcName = "SendOutlookMessage"

blnOutlookInitiallyOpen = True

Set objApp = GetObject(, "Outlook.Application")
If objApp Is Nothing Then
Set objApp = CreateObject("Outlook.Application")
'* Outlook wasn't open when this function started.
blnOutlookInitiallyOpen = False
End If
If Err <> 0 Then Beep: _
MsgBox "Error in " & strProcName & " (1): " _
& Err.Number & " - " & Err.Description: _
Err.Clear: _
GoTo Exit_Section

The error is: Error in SendOutlookMessage(1): 429 - ActiveX component
can't
create object.

I have set a reference to Microsoft Outlook 12 Object Library and tried
with
both Outlook open and closed before running it. I also moved it onto an
Access 2000 machine and had the same error.

Can anyone see a problem?

I think the problem is that you are mixing up early and late binding. Change
this line:

Dim objApp As Outlook.Application

to:

Dim objApp As Object
 
G

Guest

Thanks for the suggestion but no success. I created a new database to do
some testing with the following module

Sub test()

Dim objApp As Object
Dim blnOutlookInitiallyOpen As Boolean

On Error Resume Next

blnOutlookInitiallyOpen = True

Set objApp = GetObject(, "Outlook.Application")
If objApp Is Nothing Then
Set objApp = CreateObject("Outlook.Application")
' Outlook wasn't open when this function started.
blnOutlookInitiallyOpen = False
End If

If Err <> 0 Then Beep: _
MsgBox "Error in " & strProcName & " (1): " _
& Err.Number & " - " & Err.Description: _

End Sub

References are
- Visual Basic for Applications
- Microsoft Access 12.0 Object Library
- Microsoft Outlook 12.0 Object Library
- OLE Automation
- Microsoft DAO 3.6 Object Library

I am not sure I really understand early and late binding in spite of some
technical stuff I have read but it doesn't seem to change the situation.
Still get error 429 - Active X component can't create object.
 
G

Guest

Seems I managed to solve the problem on my own. The answer seemed to be to
run Office Diagnostics in Access 2007. It didn't report any errors but after
running that, suddenly objects were recognised. I had never heard of it
before but found a post on a newsgroup to either run Office Diagnostics in
Office 2007 or Detect and Repair in earlier versions. Thanks to Sue Mosher.
Check
http://www.devnewsgroups.net/group/microsoft.public.office.developer.outlook.vba/topic58421.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top