'Run-time error 13: Type mismatch' occurs for CreateObject("Outlook.Application") (1 Viewer)

aviateur

New member
Local time
Today, 04:51
Joined
Oct 10, 2008
Messages
6
'Run-time error 13: Type mismatch' occurs for CreateObject("Outlook.Application")

Greetings Access Colleagues:

The code snippet below fails with the error, 'Run-time error 13: Type mismatch'. I have perused many sites and forums during the past few hours but without securing a fix for this problem. My software environment is Windows XP SP3 and Microsoft Office 2003 Professional.

I have verified that the Microsoft Outlook 11.0 Object Library reference is, indeed, selected. The following test verifies this. When I enter the beginning of the statement, "Dim objOutlook as Outlook.", the dropdown list of properties appears, of which 'Application' is a choice. When I deselect the object library reference, the dropdown list does not appear.

My larger goal is to employ the VBA automation feature within Access 2003 to send Outlook 2003 email but first things first. The purpose of my query is to determine how to set the 'Outlook.Application' object variable for subsequent use within my application. Thanks in advance for any help rendered.

Cheers,
Lawrence

_____

Sub AutomationTest()

Dim objOutlook As Outlook.Application
Dim objNameSpace As Outlook.NameSpace

On Error GoTo Error1:

'*** This is the code line that fails ***
Set objOutlook = CreateObject("Outlook.Application")

Exit Sub

Error1:
MsgBox Err.Number, Err.Description

End Sub
 

CyberLynx

Stuck On My Opinions
Local time
Today, 04:51
Joined
Jan 31, 2008
Messages
585
Re: 'Run-time error 13: Type mismatch' occurs for CreateObject("Outlook.Application")

Try this.........

Dim OutlookObject As New Outlook.Application
Dim OutlookMail As MailItem

Set OutlookObject = New Outlook.Application
Set OutlookMail = OutlookObject.CreateItem(olMailItem)


.
 

aviateur

New member
Local time
Today, 04:51
Joined
Oct 10, 2008
Messages
6
Re: 'Run-time error 13: Type mismatch' occurs for CreateObject("Outlook.Application")

Try this.........

Dim OutlookObject As New Outlook.Application
Dim OutlookMail As MailItem

Set OutlookObject = New Outlook.Application
Set OutlookMail = OutlookObject.CreateItem(olMailItem)


.
No Joy ... This suggestion yields the same 'type mismatch' result.

Cheers,
Lawrence
 

CyberLynx

Stuck On My Opinions
Local time
Today, 04:51
Joined
Jan 31, 2008
Messages
585
Re: 'Run-time error 13: Type mismatch' occurs for CreateObject("Outlook.Application")

Then it must be something with your References. Move it up in the references chain. Open the References Window from within the VBA IDE and select the Microsoft Outlook 11.0 Object Library and click on the UP button located on the Left side of the list a couple times.

See if that helps.

The code I provided in my last post does work.

.
 

aviateur

New member
Local time
Today, 04:51
Joined
Oct 10, 2008
Messages
6
Re: 'Run-time error 13: Type mismatch' occurs for CreateObject("Outlook.Application")

Cyberlynx, Hi:

Thank you for the replies. I tried your approach and mine again after your 'priority order' suggestion. Both fail in my software environment. I had a 'grasping at straws' moment this afternoon and did run the 'Repair' option from the installation CD. That had no effect either.

Regarding your priority reference suggestion. I did move the Outlook object library as high as was permitted. It ended up in the 3rd slot. The items selected in my references list in order are:

. Visual Basic for Applications
. Microsoft Access 11.0 Object Library
. Microsoft Outlook 11.0 Object Library
. Microsoft Scripting Runtime
. Microsoft ActiveX Data Objects 2.8 Library
. Microsoft ADO Ext. 2.8 for DDL and Security

Cheers,
Lawrence
 

CyberLynx

Stuck On My Opinions
Local time
Today, 04:51
Joined
Jan 31, 2008
Messages
585
Re: 'Run-time error 13: Type mismatch' occurs for CreateObject("Outlook.Application")

Just off hand...do you have the Microsoft Outlook 10.0 Object Library listed within the References List? If so.....remove the Microsoft Outlook 11.0 Object Library and try the Microsoft Outlook 10.0 Object Library instead. Grasping at straws here too now. This has got to be something simple. :confused:

.
 
Last edited:

aviateur

New member
Local time
Today, 04:51
Joined
Oct 10, 2008
Messages
6
Re: 'Run-time error 13: Type mismatch' occurs for CreateObject("Outlook.Application")

CyberLynx, Hi:

In the references list, I did not find a Microsoft Outlook 10.0 Object Library. I did, however, find an unselected Microsoft Office 10.0 Object Library, which I selected and promoted to various positions to the top of the list. Unfortunately, the results yielded are still the same 'type mismatch' as before. I agree with you when you say this has got to be something simple. I am continuing to explore.

Cheers,
Lawrence
 

CyberLynx

Stuck On My Opinions
Local time
Today, 04:51
Joined
Jan 31, 2008
Messages
585
Re: 'Run-time error 13: Type mismatch' occurs for CreateObject("Outlook.Application")

I'm afraid I am not much help to you with regards to this particular situation since I can not get this error. I don't get an error with your code but then again, I don't use the 11.0 library. I use the 10.0 library.

Perhaps the Microsoft Outlook 11.0 Object Library you are using isn't properly registered with the system. Perhaps try reinstalling Outlook. or re-register the Library using RegSrv32.exe.

If the Library is not is not active then the error:

User defined Type not defined

would be generated.

The only other thing I can think of is, and this may seem a "little off the wall" but,.....is Outlook installed on your PC? Has it ever been used (run)? Sometimes automation won't work if the application you are connecting to has never been run before.

If you find the solution to this problem aviateur then I would definitely like to hear about it.

.
 

ajetrumpet

Banned
Local time
Today, 06:51
Joined
Jun 22, 2007
Messages
5,640
Re: 'Run-time error 13: Type mismatch' occurs for CreateObject("Outlook.Application")

I tried to reproduce this as well, and I couldn't for some reason. Actually, nothing happened for me. It was strange. Something started, but the process never did in the task manager. There has to be something wrong with your references sir. I can think of two things:

1) do you have more than one office version installed on your machine?
2) take a look here and try what I found out there: http://www.access-programmers.co.uk/forums/showthread.php?t=157229
 

aviateur

New member
Local time
Today, 04:51
Joined
Oct 10, 2008
Messages
6
Re: 'Run-time error 13: Type mismatch' occurs for CreateObject("Outlook.Application")

CyberLynx, Hi:

I did repair / reinstall Microsoft Office 2003 Professional Edition, which includes Access and Outlook, yesterday. Regarding Outlook, I use it everyday as my mail application at home. This is a peculiar problem but I'm afraid I have exhausted all of my resources. Should I come across the solution, I will pass it along to you. Thanks for your help.

Cheers,
Lawrence
 

aviateur

New member
Local time
Today, 04:51
Joined
Oct 10, 2008
Messages
6
Re: 'Run-time error 13: Type mismatch' occurs for CreateObject("Outlook.Application")

Adam, Hi:

I only run one version of the Office products. I reviewed the link you referenced. I attempted to reference the executable files but was stopped from doing so. The error message 'Can't add a reference to the specified file' is returned by Visual Basic.

Cheers,
Lawrence
 

ajetrumpet

Banned
Local time
Today, 06:51
Joined
Jun 22, 2007
Messages
5,640
Re: 'Run-time error 13: Type mismatch' occurs for CreateObject("Outlook.Application")

I'm out of answers then as well. Is your program perhaps corrupt? Maybe you should try a reinstall of office? I know that is extreme, but at this point I think I would actually do that...
 

LPurvis

AWF VIP
Local time
Today, 12:51
Joined
Jun 16, 2008
Messages
1,269
Re: 'Run-time error 13: Type mismatch' occurs for CreateObject("Outlook.Application")

Yeah - I'd suggest scrubbing your app and bringing everything in anew - (probably from text exports) decompiling, recompiling, compacting and then seeing where you are.
For now - you can switch to late binding.
Dim OutlookObject As Object
Do that before testing/distributing - as you'll lose intellisense for design time work which probably isn't what you want.
 

nIGHTmAYOR

Registered User.
Local time
Today, 04:51
Joined
Sep 2, 2008
Messages
240
Re: 'Run-time error 13: Type mismatch' occurs for CreateObject("Outlook.Application")

was right about to suggest that Dim OutlookObject As Object but then i recalled a thread i engaged in erlier that the user had all sorts of bizercal problems with outlook object as well that were all solved by mistake on uninstalling his antivirus. why i wouldnt suggest why you wouldnt invest more time in finding out the data type of object for it seems that on your set statment of outlook.application the object return null value which is a sign of a halted function.
now if uninstalling the antivirus doesnt help as a final resort post your references priority. sometimes a reference with higher priority can blow everything up for the rest.
Regards.
 

nIGHTmAYOR

Registered User.
Local time
Today, 04:51
Joined
Sep 2, 2008
Messages
240
Re: 'Run-time error 13: Type mismatch' occurs for CreateObject("Outlook.Application")

further more why an antivirus would intervene with outlook is that worms rely heavily on outlook.automation object in their infection spread process . so it might be as a precaution that some antiviruses would disable the automation functions, others would just mess things up on cleaning of an infection but then u mentioned you reinstalled office. Now i would suggest removing your antivirus (for test purpose only :) ) reinstall ur office and then test how things go from there.
 

CyberLynx

Stuck On My Opinions
Local time
Today, 04:51
Joined
Jan 31, 2008
Messages
585
Re: 'Run-time error 13: Type mismatch' occurs for CreateObject("Outlook.Application")

Reference priorities have already been played with in this situation.
Anti-Virus....good point nIGHTmAYOR. Could very well be, mind you, I'm not sure about anyone else but I have never had a problem with any of my anti-viral applications and I've run about four different makes over time. Perhaps I did and never thought of it.

Good point and definitely something to look out for in those ...... real odd occasions.

.
 

LPurvis

AWF VIP
Local time
Today, 12:51
Joined
Jun 16, 2008
Messages
1,269
Re: 'Run-time error 13: Type mismatch' occurs for CreateObject("Outlook.Application")

I've never had AV interfere with me personally - though have had older or lesser known AV installs interfere at external installations. Though switching to late binding is worthwhile here because you'll determine if it's the assignment to the declared object type variable that's failing (in which case AV is less likely) or if the object returned (now into a generic Object) is empty (has failed) and hence why the assignment to the declared type failed.
In other words - have you tried the late binding suggestion?
 

jal

Registered User.
Local time
Today, 04:51
Joined
Mar 30, 2007
Messages
1,709
Re: 'Run-time error 13: Type mismatch' occurs for CreateObject("Outlook.Application")

Instead of using CreateObject, maybe he should use Shell to start the file Outlook.Exe, and then use GetObject to get a handle on the running instance. I say this because I have it in my notes that CreateObject can sometimes throw errors where GetObject succeeds.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom