Invalid use of object with .Find method??

J

Jack

Hello all,

Using ADO in Access97, I'm trying to use the .Find method
on a recordset. The recordset was opened with adOpenStatic
and adLockReadOnly. My code won't run, it keeps telling
me "invalid use of object", and highlights the "rcs.Find"
part of my code. I can't seem to figure out what's
causing this problem. I have the proper reference to the
Microsoft ADO library. I can't use the Seek method as my
data source doesn't support Seek.

Thanks for any help/advice!

-Jack
 
D

Dirk Goldgar

Jack said:
Hello all,

Using ADO in Access97, I'm trying to use the .Find method
on a recordset. The recordset was opened with adOpenStatic
and adLockReadOnly. My code won't run, it keeps telling
me "invalid use of object", and highlights the "rcs.Find"
part of my code. I can't seem to figure out what's
causing this problem. I have the proper reference to the
Microsoft ADO library. I can't use the Seek method as my
data source doesn't support Seek.

Thanks for any help/advice!

-Jack

Do you also have a reference to the DAO library, as well as ADO? How is
your recordset object declared? Maybe you need to preface the type with
the library name, like this:

Dim rcs As ADODB.Recordset

If that's not it, please post your code.
 
D

Dirk Goldgar

Jack said:
I do also have a reference to the DAO library, but I've
tried it without it as well and still get the same error.

Here is the relevant code to the recordset I'm trying to
use the .Find method on:



Dim db As New ADODB.Connection
Dim rcs As New ADODB.Recordset
Dim sql As String
Dim AgntID As Long

db.Open "MyDataSource DSN", "MyUsername", "MyPassword"

sql = ""SELECT agtprof.AGENT_ID, agtprof.SENIORITY_DATE,
agtprof.SENIORITY_EXT " & _
"FROM agtprof " & _
"ORDER BY agtprof.AGENT_ID"

rcs.Open sql, db, adOpenStatic, adLockReadOnly, adCmdText
AgntID = 2976
rcs.Find "AGENT_ID = '" & AgntID & "'"



Also, I've tried just using the .Find opening the
recordset straight to a table instead of using an sql
statement like this:

rcs.Open "agtprof", db, adOpenStatic, adLockReadOnly,
adCmdTableDirect

But I still get the error.

Thanks again for any help/advice

Hmm. I don't see anything obviously wrong with it (though I'm more
familiar with DAO than ADO), except the extra leading double-quote on
this line as you posted it:
sql = ""SELECT agtprof.AGENT_ID, agtprof.SENIORITY_DATE,

But that should raise a compile error, so I find it hard to believe
that's your actual code. On the other hand, if you didn't post your
exact, actual code, maybe it means there's an error you edited out. Can
you verify, using the Locals window and stepping through the code, that
the recordset is properly opened, with the correct SQL statement/
 

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