Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Err 13 Type mismatch while filling up a recordset

Status
Not open for further replies.

Smarty

Programmer
Apr 12, 2001
191
0
0
BE
I have the following code:


Dim sqlstring As String

sqlstring = "select * from GuidelineCategories order by GuidelineCategoryID"
Dim db As Variant
Dim rst As Recordset

Set db = CurrentDb
Set rst = db.openrecordset(sqlstring)

rst.MoveFirst
While Not rst.EOF
If rst.Fields("ParentID") = 0 Then
CategoryTree.Nodes.Add , , rst.Fields("GuidelineCategoryID"), rst.Fields("Category")
Else
CategoryTree.Nodes.Add rst.Fields("ParentID"), tvwChild, rst.Fields("GuidelineCategoryID"), rst.Fields("Category")
End If
rst.MoveNext

Wend



But I get an Err 13 Type mismatch in the following line:

Set rst = db.openrecordset(sqlstring)

I tripple checked the column and table names, they are correct. Any idea why this is not working?
 
I think db should Dim db as Database

Give it a shot
Scoty ::) "Learn from others' mistakes. You could not live long enough to make them all yourself."
-- Hyman George Rickover (1900-86),
 
i suspect that you have your ADO library priorized before your DAO library in the References.

go to Tools --> References and re-priorize your libraries and make sure that your DAO is listed higher than ADO.

however, if you need to reference and use both DAO and ADO Recordset objects, dimension the objects explicitly as:

Dim rst As DAO.Recordset
Dim rst As ADODB.Recordset

hope this helps! TestDrive
 
Bingo! I was having the same type mismatch error and by moving the you have your DAO library priorized before the ADO library in the References the problem was solved!

This is a very frustrating error because it seems there is no way to track it down unless you're "in the know"

 
Another way of solving it is by declaring your variables with the dao...

dim rs as dao.recordset
dim db as dao.database

This eleminates a question if a different programmer needs to look at your code...

--James junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top