type mismatch - 13

C

Chris

I'm getting this error message on an Access 2007 run database that was coded
originally in Access 2003. If I run the report on an Office 2003 PC no
problem. If I do it on an Office 2007 PC I get the error.

Mirosoft had this Information

***********************************
http://support.microsoft.com/kb/927678/en-us

Error message when you convert a database file from an earlier version of
Access into an Access 2007 file: "Run-time error '13': Type mismatch"
View products that this article applies to.
Article ID : 927678
Last Review : October 15, 2007
Revision : 1.3
On This Page
SYMPTOMS
CAUSE
WORKAROUND
Method 1
Method 2
Method 3
STATUS
SYMPTOMS
When you convert a database file from an earlier version of Microsoft Access
into a Microsoft Office Access 2007 file, the application may stop responding
if you try to run or compile code that uses Data Access Objects (DAO).
Additionally, you may receive the following error message:
Run-time error ‘13’:
Type mismatch
Back to the top
CAUSE
This problem occurs because the order of database references is not
preserved when the database file is converted.
Back to the top
WORKAROUND
To work around this problem, use one of the following methods:
Back to the top
Method 1
In the References dialog box, make sure that Microsoft Office 2007 Access
database engine Object Library is higher in priority than Microsoft ActiveX
Data Objects. To do this, follow these steps:1. Start Access 2007.
2. Click the Microsoft Office Button, and then click Open.
3. In the Open dialog box, locate and select <DatabaseName>, and then click
Open.
4. On the Database Tools menu, click Visual Basic in the Macro group to open
Visual Basic Editor (VBE).
Note You may also press ALT+F11 to open VBE.
5. On the Tools menu, click References.
6. In the References - <DatabaseName> dialog box, click Microsoft Office
2007 Access database engine Object Library.
7. Click the Priority arrow to move Microsoft Office 2007 Access database
engine Object Library above Microsoft ActiveX Data Objects, and then click
OK.
Back to the top
Method 2
If you must reference and use both DAO and ActiveX Data Objects (ADO) object
libraries, dimension the objects explicitly as follows: Dim adoRS As
ADODB.Recordset
Dim daoRS As DAO.Recordset
Back to the top
Method 3
If you are not using an ADO object library, clear the reference to the
library. To do this, follow these steps:1. Start Access 2007.
2. Click the Microsoft Office Button, and then click Open.
3. In the Open dialog box, locate and select <DatabaseName>, and then click
Open.
4. On the Database Tools menu, click Visual Basic in the Macro group to open
VBE.
Note You may also press ALT+F11 to open VBE.
5. On the Tools menu, click References.
6. In the References - <DatabaseName> dialog box, click to clear Microsoft
ActiveX Data Objects, and then click OK.
*********************************

This is the actual code that it Bombs out on:

***************************************
Private Sub Report_Open(Cancel As Integer)
On Error GoTo Err_Report_Open
Dim rst As ADODB.Recordset
Dim fld As ADODB.Field
Dim ctl As Control
Dim X As Integer

Set rst = New ADODB.Recordset
rst.Open "[Server NLM Files_Crosstab]", CurrentProject.Connection,
adOpenDynamic, adLockOptimistic

With rst
For Each fld In rst.Fields
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox And ctl.Name = X Then
If fld.Name = "NLM Name" Then
X = X - 1
End If
ctl.ControlSource = fld.Name
Exit For
ElseIf TypeOf ctl Is Label And Right(ctl.Name, 2) = X Then
ctl.Caption = fld.Name
End If
Next ctl
X = X + 1
Next fld
End With
Exit_Report_Open:
Exit Sub
Err_Report_Open:
MsgBox Err.Description & " - " & Err.Number
Resume Exit_Report_Open

End Sub
*****************************************
 
T

Tom van Stiphout

On Mon, 30 Jun 2008 21:15:00 -0700, Chris

In your case, since your code is using ADO rather than DAO (which
Q927678 assumes), you need to check the ADO library and uncheck the
DAO library.

-Tom.


I'm getting this error message on an Access 2007 run database that was coded
originally in Access 2003. If I run the report on an Office 2003 PC no
problem. If I do it on an Office 2007 PC I get the error.

Mirosoft had this Information

***********************************
http://support.microsoft.com/kb/927678/en-us

Error message when you convert a database file from an earlier version of
Access into an Access 2007 file: "Run-time error '13': Type mismatch"
View products that this article applies to.
Article ID : 927678
Last Review : October 15, 2007
Revision : 1.3
On This Page
SYMPTOMS
CAUSE
WORKAROUND
Method 1
Method 2
Method 3
STATUS
SYMPTOMS
When you convert a database file from an earlier version of Microsoft Access
into a Microsoft Office Access 2007 file, the application may stop responding
if you try to run or compile code that uses Data Access Objects (DAO).
Additionally, you may receive the following error message:
Run-time error ‘13’:
Type mismatch
Back to the top
CAUSE
This problem occurs because the order of database references is not
preserved when the database file is converted.
Back to the top
WORKAROUND
To work around this problem, use one of the following methods:
Back to the top
Method 1
In the References dialog box, make sure that Microsoft Office 2007 Access
database engine Object Library is higher in priority than Microsoft ActiveX
Data Objects. To do this, follow these steps:1. Start Access 2007.
2. Click the Microsoft Office Button, and then click Open.
3. In the Open dialog box, locate and select <DatabaseName>, and then click
Open.
4. On the Database Tools menu, click Visual Basic in the Macro group to open
Visual Basic Editor (VBE).
Note You may also press ALT+F11 to open VBE.
5. On the Tools menu, click References.
6. In the References - <DatabaseName> dialog box, click Microsoft Office
2007 Access database engine Object Library.
7. Click the Priority arrow to move Microsoft Office 2007 Access database
engine Object Library above Microsoft ActiveX Data Objects, and then click
OK.
Back to the top
Method 2
If you must reference and use both DAO and ActiveX Data Objects (ADO) object
libraries, dimension the objects explicitly as follows: Dim adoRS As
ADODB.Recordset
Dim daoRS As DAO.Recordset
Back to the top
Method 3
If you are not using an ADO object library, clear the reference to the
library. To do this, follow these steps:1. Start Access 2007.
2. Click the Microsoft Office Button, and then click Open.
3. In the Open dialog box, locate and select <DatabaseName>, and then click
Open.
4. On the Database Tools menu, click Visual Basic in the Macro group to open
VBE.
Note You may also press ALT+F11 to open VBE.
5. On the Tools menu, click References.
6. In the References - <DatabaseName> dialog box, click to clear Microsoft
ActiveX Data Objects, and then click OK.
*********************************

This is the actual code that it Bombs out on:

***************************************
Private Sub Report_Open(Cancel As Integer)
On Error GoTo Err_Report_Open
Dim rst As ADODB.Recordset
Dim fld As ADODB.Field
Dim ctl As Control
Dim X As Integer

Set rst = New ADODB.Recordset
rst.Open "[Server NLM Files_Crosstab]", CurrentProject.Connection,
adOpenDynamic, adLockOptimistic

With rst
For Each fld In rst.Fields
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox And ctl.Name = X Then
If fld.Name = "NLM Name" Then
X = X - 1
End If
ctl.ControlSource = fld.Name
Exit For
ElseIf TypeOf ctl Is Label And Right(ctl.Name, 2) = X Then
ctl.Caption = fld.Name
End If
Next ctl
X = X + 1
Next fld
End With
Exit_Report_Open:
Exit Sub
Err_Report_Open:
MsgBox Err.Description & " - " & Err.Number
Resume Exit_Report_Open

End Sub
*****************************************
 
C

Chris

How can I re-write this code to be DAO rather than ADO


***************************************
Private Sub Report_Open(Cancel As Integer)
On Error GoTo Err_Report_Open
Dim rst As ADODB.Recordset
Dim fld As ADODB.Field
Dim ctl As Control
Dim X As Integer

Set rst = New ADODB.Recordset
rst.Open "[Server NLM Files_Crosstab]", CurrentProject.Connection,
adOpenDynamic, adLockOptimistic

With rst
For Each fld In rst.Fields
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox And ctl.Name = X Then
If fld.Name = "NLM Name" Then
X = X - 1
End If
ctl.ControlSource = fld.Name
Exit For
ElseIf TypeOf ctl Is Label And Right(ctl.Name, 2) = X Then
ctl.Caption = fld.Name
End If
Next ctl
X = X + 1
Next fld
End With
Exit_Report_Open:
Exit Sub
Err_Report_Open:
MsgBox Err.Description & " - " & Err.Number
Resume Exit_Report_Open

End Sub
*****************************************
 
D

Douglas J. Steele

I'm assuming Server NLM Files_Crosstab is a saved query. Try:

Private Sub Report_Open(Cancel As Integer)
On Error GoTo Err_Report_Open
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
Dim fld As DAO.Field
Dim ctl As Control
Dim X As Integer

Set qdf = CurrentDb.QueryDefs("Server NLM Files_Crosstab")
Set rst = qdf.OpenRecordset

With rst
For Each fld In rst.Fields
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox And ctl.Name = X Then
If fld.Name = "NLM Name" Then
X = X - 1
End If
ctl.ControlSource = fld.Name
Exit For
ElseIf TypeOf ctl Is Label And Right(ctl.Name, 2) = X Then
ctl.Caption = fld.Name
End If
Next ctl
X = X + 1
Next fld
End With

Exit_Report_Open:
Exit Sub

Err_Report_Open:
MsgBox Err.Description & " - " & Err.Number
Resume Exit_Report_Open

End Sub

I must confess, though, that I have no idea what you're trying to do! Are
you simply trying to cope with the fact that your crosstab query doesn't
always have the same field names? You can make it always return the same
fields by using an IN clause as part of the PIVOT clause of the SQL.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Chris said:
How can I re-write this code to be DAO rather than ADO


***************************************
Private Sub Report_Open(Cancel As Integer)
On Error GoTo Err_Report_Open
Dim rst As ADODB.Recordset
Dim fld As ADODB.Field
Dim ctl As Control
Dim X As Integer

Set rst = New ADODB.Recordset
rst.Open "[Server NLM Files_Crosstab]", CurrentProject.Connection,
adOpenDynamic, adLockOptimistic

With rst
For Each fld In rst.Fields
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox And ctl.Name = X Then
If fld.Name = "NLM Name" Then
X = X - 1
End If
ctl.ControlSource = fld.Name
Exit For
ElseIf TypeOf ctl Is Label And Right(ctl.Name, 2) = X Then
ctl.Caption = fld.Name
End If
Next ctl
X = X + 1
Next fld
End With
Exit_Report_Open:
Exit Sub
Err_Report_Open:
MsgBox Err.Description & " - " & Err.Number
Resume Exit_Report_Open

End Sub
*****************************************
 

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