"Type Mismatch" error message when you run a VBA macro in a 64-bit version of an Office 2010 application

Article translations Article translations
Article ID: 983246 - View products that this article applies to.
Support for Windows Vista Service Pack 1 (SP1) ends on July 12, 2011. To continue receiving security updates for Windows, make sure that you are running Windows Vista with Service Pack 2 (SP2). For more information, visit the following Microsoft webpage:
Support is ending for some versions of Windows
The hotfix that resolves a similar issue in Windows 7 SP1 and Windows Server 2008 R2 SP1 is described in Microsoft Knowledge Base article 2640696. For more information about KB 2640696, click the following article number to view the article in the Microsoft Knowledge Base:
2640696 An ADO-based application that is compiled in Windows 7 SP1 or in Windows Server 2008 R2 SP1 does not run in earlier versions of Windows
Expand all | Collapse all

On This Page

Symptoms

Assume that you have a Microsoft Visual Basic for Applications (VBA) macro that runs correctly on a 32-bit version of a Microsoft Office application. However, this VBA macro does not run correctly in a 64-bit version of a Microsoft Office 2010 application in a 64-bit version of Windows.

Typically, this problem occurs when the VBA macro uses some Microsoft ActiveX Data Objects (ADO) APIs that are platform-dependent. For example, you run a VBA macro that uses the RecordCount property of an ADO Recordset object in a way that resembles the following:
Dim rs as ADODB.Recordse
LONG recordCount


...
recordCount = rs.RecordCount
In this example, you receive a "Type Mismatch" error message when you run this macro on a 64-bit version of an Office 2010 application.

Notes
  • You can install the 64-bit version of Office 2010 in the following Windows operating systems:
    • 64-bit editions of Windows Server 2003 Service Pack 2 that have MSXML 6.0 installed
    • x64-based editions of Windows Vista Service Pack 1 and later versions
    • 64-bit editions of Windows Server 2008 and later versions
    • x64-based editions of Windows 7
    • Windows Server 2008 R2
  • To view a list of ADO APIs that are platform dependent, see the "More information" section.

Cause

Some ADO APIs are platform dependent in ADO 2.7 and later versions. On 64-bit versions of Windows, these ADO APIs process arguments by using a 64-bit data type (such as the LONGLONG data type). However, applications that use these APIs still use the LONG data type. Therefore, you receive a "Type Mismatch" error message when you try to run the macro.

More information

Notes
  • In Windows Vista, Windows Server 2008, or in later versions of Windows, the ADO 6.0 type library and the ADO 6.1 type library share the same type library ID (LIBID). Visual Basic can only display one of these in the Available Reference list at a time. To manually locate the ADO 6.0 type library (Msado60.tlb) in this situation, browse to the following location: %program files%\common files\system\ado. Visual Basic automatically displays the ADO 6.0 type library in the Available References list if the reference to the ADO 6.0 type library was added to current project.
  • Consider the scenario where you are a C++ developer, and you include the following line of code in the application:
     
    #import msado15.dll
    


    Consider the scenario that you are not using MSJRO, and you recompile the application on Windows Vista, on Windows Server 2008, or on later versions of Windows. The compiled application must run in Windows Vista, in Windows Server 2008, or in later versions of Windows. In this scenario, you must change #import msado15.dll to the following:
     
    #import msado60.tlb
    

    Consider the scenario that you are using MSJRO, and you recompile an application that must run in Windows Vista, in Windows Server 2008, or in a later version of Windows. In this scenario, you must change #import msado15.dll to the following:
     
    #import msado28.tlb
    

    Consider the scenario that you recompile your application on Windows XP or on Windows Server 2003. Or, the recompiled application must run in Windows XP or in Windows Server 2003. In this scenario, you must change #import msado15.dll to the following:
     
    #import msado28.tlb
    
  • If you are a C++, VB6, or .NET developer and if you applied "Method 1" in the "Workaround" section that was described in Microsoft Knowledge Base article 2517589 (this workaround was removed after update 2640696 was released), you do not have to change the code. For more information about KB 2517589, click the following article number to view the article in the Microsoft Knowledge Base:
    2517589 An ADO application does not run on down-level operating systems after you recompile it on a computer that is running Windows 7 SP 1 or Windows Server 2008 R2 SP 1 or that has update 983246 installed

Resolution

To address this issue, install the 64-bit version of the hotfix that matches the operating system on the affected computer.

A supported hotfix is available from Microsoft. However, this hotfix is intended to correct only the problem that is described in this article. Apply this hotfix only to systems that are experiencing the problem described in this article. This hotfix might receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next software update that contains this hotfix.

If the hotfix is available for download, there is a "Hotfix download available" section at the top of this Knowledge Base article. If this section does not appear, contact Microsoft Customer Service and Support to obtain the hotfix.

Note If additional issues occur or if any troubleshooting is required, you might have to create a separate service request. The usual support costs will apply to additional support questions and issues that do not qualify for this specific hotfix. For a complete list of Microsoft Customer Service and Support telephone numbers or to create a separate service request, visit the following Microsoft website:
http://support.microsoft.com/contactus/?ws=support
Note The "Hotfix download available" form displays the languages for which the hotfix is available. If you do not see your language, it is because a hotfix is not available for that language.

Prerequisites

There are no prerequisites for applying this hotfix.

Registry information

To use the hotfix in this package, you do not have to make any changes to the registry.

Restart requirement

You may have to restart the computer after you apply this hotfix.

Hotfix replacement information

This hotfix does not replace a previously released hotfix.

File information

Click here to view or hide detailed information

Status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

More information

This hotfix includes both platform-dependent API and platform-independent API for ADO. The following table explains the differences between different versions of type libraries:
Collapse this tableExpand this table
ADO Type libraryFile nameSupported ADO API
Microsoft ActiveX Data Objects 2.0 LibraryMsado20.tlbPlatform-dependent API
Microsoft ActiveX Data Objects 2.1 LibraryMsado21.tlbPlatform-dependent API
Microsoft ActiveX Data Objects 2.5 LibraryMsado25.tlbPlatform-dependent API
Microsoft ActiveX Data Objects 2.6 LibraryMsado26.tlbPlatform-dependent API
Microsoft ActiveX Data Objects 2.7 LibraryMsado27.tlbPlatform-dependent API
Microsoft ActiveX Data Objects 2.8 LibraryMsado28.tlbPlatform-dependent API
Microsoft ActiveX Data Objects 6.0 LibraryMsado60.tlb (available only in Windows Vista or in Windows Server 2008, or in later versions of Windows)Platform-dependent API
Microsoft ActiveX Data Objects 6.1 LibraryEmbedded in Msado15.dllPlatform-independent API
Microsoft ActiveX Data Objects Recordset 2.8 LibraryMsador28.tlb (available in Windows Vista or in Windows Server 2008, or in later versions of Windows; or embedded in Msador15.dll in Windows XP or in Windows Server 2003)Platform-dependent API (subsets of API compared to Microsoft ActiveX Data Objects 2.8 Library)
Microsoft ActiveX Data Objects Recordset 6.0 Libraryembedded in Msador15.dll (available only in Windows Vista or in Windows Server 2008, or in later versions of Windows)Platform-dependent API (subsets of API compared to Microsoft ActiveX Data Objects 6.0 Library)
Note Do not use the old versions of the type libraries when you recompile your applications. Use Microsoft ActiveX Data Objects 6.1 Library when you need platform interoperability. Generally, use Microsoft ActiveX Data Objects 6.0 Library that is included with Windows Vista or for Windows Server 2008, or for later versions of Windows and Microsoft ActiveX Data Objects 2.8 Library that is included with Windows XP or for Windows Server 2003.

The following table lists ADO APIs that are platform-dependent. Additionally, a corresponding platform-independent API is included with the ADO 6.1 type library.
Collapse this tableExpand this table
ADO objectADO property or method
ADOCommmandCreateParameter(ADO_LONGPTR Size)
ADORecordsetMaxRecords ([out, retval] ADO_LONGPTR *plMaxRecords)

MaxRecords ([in] ADO_LONGPTR lMaxRecords)

RecordCount ([out, retval] ADO_LONGPTR *pl)

Move ([in] ADO_LONGPTR NumRecords)

PageCount ([out, retval] ADO_LONGPTR *pl)

Absolutepage([out,retval] PositionEnum_Param *pl)

Absolutepage([in] PositionEnum_Param l)

Find ([in] ADO_LONGPTR SkipRecords)

AbsolutePosition([in] PositionEnum_Param l)

AbsolutePosition([out, retval] PositionEnum_Param *pl)
ADOParameterSize([in] ADO_LONGPTR l)

Size([out,retval] ADO_LONGPTR *pl)
ADOFieldActualSize( [out, retval] ADO_LONGPTR *pl)

DefinedSize(out ADO_LONGPTR *pl)
ADOFieldsAppend( [in] ADO_LONGPTR DefinedSize)
ADOStreamSize ( [out, retval] ADO_LONGPTR *pSize )

Position ( [out, retval] ADO_LONGPTR *pPos )

CopyTo ([in] ADO_LONGPTR CharNumber)

32-bit or 64-bit platform interoperability

If you compile a VBA-based application that works with 64-bit Office, and if you referenced one of the following type libraries in the application, you must reference the platform independent type library by changing the reference into "Microsoft ActiveX Data Objects 6.1 Library":
  • Microsoft ActiveX Data Objects 2.0 Library
  • Microsoft ActiveX Data Objects 2.1 Library
  • Microsoft ActiveX Data Objects 2.5 Library
  • Microsoft ActiveX Data Objects 2.6 Library
  • Microsoft ActiveX Data Objects 2.7 Library
  • Microsoft ActiveX Data Objects 2.8 Library
  • Microsoft ActiveX Data Objects Recordset 2.8 Library
  • Microsoft ActiveX Data Objects Recordset 6.0 Library
If you have ever changed your code from LONG to ADO_LONGPTR to take advantage of the platform-dependent interfaces on 64-bit platform, you must convert them back into LONG after you opt-into the platform-independent interfaces.

Caution After you have taken the dependencies on ADO 6.1 type library, you can run your recompiled application only on computers that have installed this update or the update in Microsoft Knowledge Base article 2640696. You cannot run the recompiled application on other computers. Also, if you expose an interface in your recompiled application that can be called from a remote computer and that uses any one of the ADO interfaces that are listed here (such as ADORecordset), make sure that the remote computer has installed this update or the update in KB article 2640696.

Currently, we recommend that you change to the ADO 6.1 type library only when you have a cross-platform scenario, such as Office 32-bit and 64-bit interoperability. Otherwise, you should not use the ADO 6.1 type library unless you can be sure that your application will be run only on a computer that has installed this hotfix or the update in Microsoft Knowledge Base article 2640696. For more information about KB 2640696, click the following article number to view the article in the Microsoft Knowledge Base:
2640696 An ADO-based application that is compiled in Windows 7 SP1 or in Windows Server 2008 R2 SP1 does not run in earlier versions of Windows

Backward compatibility for recompiled applications

Assume that you developed an ADO application that is compatible with versions of Windows that are earlier than Windows 7 SP1 and Windows Server 2008 R2 SP1. After you install this hotfix, the recompiled application may not run on a computer that does not have this hotfix or KB 2517589 installed. This behavior occurs because the application may reference a platform-independent interface (by referencing the platform-independent type libraries - Microsoft ActiveX Data Objects 6.1 Library) that is introduced in this hotfix and KB 2517589. To avoid this recompilation issue, you have to reference the platform-dependent type library (for example, Microsoft ActiveX Data Objects 6.0 Library when the application must run in Windows Vista or in Windows Server 2008 or in later versions of Windows, or Microsoft ActiveX Data Objects 2.8 Library when the application must run in Windows XP or in Windows Server 2003) in your project.

Notes
  • In Windows Vista or in Windows Server 2008, or in later versions of Windows, the ADO 6.0 type library and ADO 6.1 type library share the same type library ID (LIBID). Visual Basic can only display one of them in the Available Reference list at a time. To manually locate the ADO 6.0 type library (Msado60.tlb) in this situation, browse to the location: %program files%\common files\system\ado. Visual Basic automatically displays the ADO 6.0 type library in the Available References list if the reference to the ADO 6.0 type library was added to current project.
  • If you are a C++ developer and if you include the following line of code in the application:
    #import msado15.dll
    You must change the line to the following when you recompile the application that must run in Windows Vista or in Windows Server 2008, or in later versions of Windows:
    #import msado60.tlb
    Or You must change the line to the following when you recompile the application that must run in Windows XP, or in Windows Server 2003:
    #import msado28.tlb
  • If you are a C++, VB6, or .NET developer and if you have applied "Method 1" in the "Workaround" section that is described in Microsoft Knowledge Base article 2517589, you do not have to change the code. For more information about KB 2517589, click the following article number to view the article in the Microsoft Knowledge Base:
    2517589 An ADO application does not run on down-level operating systems after you recompile it on a computer that is running Windows 7 SP 1 or Windows Server 2008 R2 SP 1 or that has KB983246 installed
For more information about ADO APIs, visit the following Microsoft Developer Network (MSDN) website:
ADO API reference
For more information about the RecordCount property of ADOs, visit the following Microsoft Developer Network (MSDN) website:
Introduction to the RecordCount property
For more information about ADO history, visit the following Microsoft Developer Network (MSDN) website:
ADO history
For more information about software update terminology, click the following article number to view the article in the Microsoft Knowledge Base:
824684 Description of the standard terminology that is used to describe Microsoft software updates

Additional file information

Click here to view or hide detailed information

Properties

Article ID: 983246 - Last Review: August 16, 2012 - Revision: 8.0
Applies to
  • Windows 7 Enterprise
  • Windows 7 Home Basic
  • Windows 7 Home Premium
  • Windows 7 Professional
  • Windows 7 Ultimate
  • Windows Server 2008 R2 Datacenter
  • Windows Server 2008 R2 Enterprise
  • Windows Server 2008 R2 Standard
  • Windows Web Server 2008 R2
  • Windows Vista Service Pack 1, when used with:
    • Windows Vista Business
    • Windows Vista Business 64-bit Edition
    • Windows Vista Enterprise
    • Windows Vista Enterprise 64-bit Edition
    • Windows Vista Home Basic
    • Windows Vista Home Basic 64-bit Edition
    • Windows Vista Home Premium
    • Windows Vista Home Premium 64-bit Edition
    • Windows Vista Ultimate
    • Windows Vista Ultimate 64-bit Edition
  • Windows Vista Service Pack 2, when used with:
    • Windows Vista Business
    • Windows Vista Business 64-bit Edition
    • Windows Vista Enterprise
    • Windows Vista Enterprise 64-bit Edition
    • Windows Vista Home Basic
    • Windows Vista Home Basic 64-bit Edition
    • Windows Vista Home Premium
    • Windows Vista Home Premium 64-bit Edition
    • Windows Vista Ultimate
    • Windows Vista Ultimate 64-bit Edition
  • Windows Server 2008 Datacenter
  • Windows Server 2008 Datacenter without Hyper-V
  • Windows Server 2008 Enterprise
  • Windows Server 2008 Enterprise without Hyper-V
  • Windows Server 2008 Standard
  • Windows Server 2008 Standard without Hyper-V
  • Windows Web Server 2008
  • Windows Server 2008 for Itanium-Based Systems
  • Microsoft Windows XP Service Pack 3
  • Microsoft Windows Server 2003 Service Pack 2
Keywords: 
kbexpertiseinter kbhotfixserver kbqfe kbfix kbautohotfix kbsurveynew kbprb KB983246

Give Feedback