Run-time error '13': Type mismatch

B

bw

I call this procedure from the Report_Open event, and am getting the error
shown on the 6th line below.
I'm trying to find out how many records (if any) are in the table
"tblSelectMainReport".
Can you explain the error, or a better way to find out the number of records
in the table?

Thanks,
Bernie

Private Sub CountTheErrors()
Dim dbs As Database, rst As Recordset, X As Integer, strName As String
Dim strDocName As String
Set dbs = CurrentDb
strDocName = "tblSelectMainReport"
Set rst = dbs.OpenRecordset(strDocName) 'ERROR HERE: Type mismatch
MsgBox rst.RecordCount
rst.Close
Set dbs = Nothing
End Sub
 
A

Allen Browne

Try:
Dim dbs As Database, rst As DAO.Recordset, X As Integer, strName As
String

Both the DAO library and the ADO library have a Recordset object. If you do
not specify which one you want, you get whichever one is listed first under
Tools | References (from a code window.)

You can solve the problem by any of the following:
a) Remove the ADO library if you don't need it.
b) Move the DAO library above ADO so it has a higher priority.
c) Explicitly disambiguate, as in the example above.

More info on which references are needed for which versions of Access:
http://allenbrowne.com/ser-38.html
 
B

bw

Thanks,Allen!

I was going to follow up with more questions about this, but I guess you new
I would, and so included the link to your explanation for "Solving Problems
with Library References".

As always, I appreciate your help.
Bernie
 

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