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

how come ADODB recordset always return NOTHING 1

Status
Not open for further replies.

jieyin

Programmer
May 22, 2003
9
US
Hi, I have a function associated with a form button (Access2000), part of it (see blow) is to find record count in a select query:


Private Sub Register_Click()
....

Dim rs As ADODB.Recordset

Set rs = New ADODB.Recordset

rs.Open "select branch_id from branches", CurrentProject.Connection

MsgBox rs.RecordCount, vbOKOnly
....

I always get -1 returned as rs.RecordCount. I suspect it is the CurrentProject.Connection, how should I set it to open my current database where the form and tables belong?

Thank you.
 
RecordCount will return -1 when ADO can't determine the number of records due to the provider or cursortype. If the tables you are selecting from reside in the same database as the form you're running the procedure from, CurrentProject.Connection should work. Try specifying the cursortype for the recordset as a static cursor.

For example:
rs.Open "select branch_id from branches", CurrentProject.Connection, adOpenStatic
 
Thanks, it works!

I also found another way to do it: reference to DAO and use
currentDB.openReordSet, looks like this way the adOpenStatic is default.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top