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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type mismatch error

Status
Not open for further replies.

Terkle

Technical User
Jul 22, 2007
18
0
0
Hello there
I'm trying to run a procedure but keep getting a 'type mismatch' error. To try and sort out the problem, I've created a 'test' db and made a simple table, query and forms and inserted the code below and it works fine.

Private Sub Form_Load()
Dim db As DAO.Database, rst As DAO.Recordset, strSQL As String
Set db = CurrentDb

Dim intNames As Integer
Dim rstNames As Recordset

Set rstNames = db.OpenRecordset("qry1Data", dbOpenDynaset)
intNames = rstNames.RecordCount


If intNames > 2 Then
MsgBox ("Blahhhhhhhhhhhh!")
Else
MsgBox ("Wooooooo!")

End If

End Sub

I imported all the objects from the 'test' db into the one I was having trouble in and when I try to open the same form that works in the 'test' db, i still get a 'Type mismatch' error.

Is anyone able to explain why this is happening?

Thank you
 
Which line of code is highlighted when in debug mode ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Sorry, I should have added that. It's the line below:

Set rstNames = db.OpenRecordset("qry1Data", dbOpenDynaset)

Thanks
 
Replace this:
Dim rstNames As Recordset
with this:
Dim rstNames As [!]DAO.[/!]Recordset

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That's why this forum is so great as there are always smart people out there who know the answers. Thanks for your help, fellas and your solution works fine.

terk.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top