type mismatch with recordset object?

D

Damion

Using Access 97. The following code is consistently
giving me a Type Mismatch error. Any explanation of why
would be most appreciated.

<begin sample code>

private sub MySub
dim db as database
dim qdef as QueryDef
dim rst as Recordset

set db = CurrentDB()
set qdef = db.QueryDefs("AQuery")
qdef.Parameters(0) = SomeValue
set rst = qdef.OpenRecordset()
'the next line causes a Type Mismatch.
'Execution never enters MyOtherSub.
MyOtherSub(rst)

end sub

private sub MyOtherSub(rs as Recordset)

end sub
 
M

Michel Walsh

HI,


Using this Access 97 code on a Access 2000 (or more recent) version produces
a type mismatch error at the line

set rst=qdef.OpenRecordset()

If so, try to change

Dim rst as Recordset

to

Dim rst As DAO.Recordset


It seems your references include both DAO and ADO and thus, a Recordset can
be supplied by two sources (ADODB.Recordset is the other source). Removing
the ambiguity, such as specifying the library, is a general solution to that
kind of problem.


If that is not the case, can you specify the line where the error occurs?


Hoping it may help,
Vanderghast, Access MVP
 
D

Douglas J. Steele

In addition to Michel's advice, try removing the parentheses in the
statement
MyOtherSub(rst)

When you are trying to invoke a subroutine, you must either use Call and
parentheses, or else no parentheses:

Call MyOtherSub(rst)

or

MyOtherSub rst
 

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