type mismatch with recordset object?

  • Thread starter Thread starter Damion
  • Start date Start date
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
 
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
 
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
 
Back
Top