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 strongm 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
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?
 
You might want to change the db to be dimmed as a database.

If that doesn't work, try changing this:
Code:
Set rst = db.openrecordset(sqlstring)
to
Code:
Set rst = Currentdb.CreateQueryDef("",sqlstring).OpenRecordSet
My example creates a temporary query, if you are using Access 97 (or higher if you have DAO objects referenced).

God Bless :)
 
I managed to do what i want with this code:

Private Sub Form_Load()
Dim sqlstring As String
Dim ParentID, GuidelineCategoryID, Category As String

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

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

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

Wend


End Sub


THANX ANYWAY!
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top