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

If I do Dim rsDoc as NEW ADODB.R

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
If I do

Dim rsDoc as NEW ADODB.Recordset

str = "SELECT * FROM Mytable WHERE ID = '" & varID & "' ORDER BY ID"

With rsDoc
.Open str, cn, adOpenStatic, adLockReadOnly, adCmdText
msgbox(.RecordCount)
End With

I get a recordcount=1 when there are NO RECORDS on the record!!! Why does this happen? I should get a zero record count!
 
Try
.Open str, cn, adOpenKeyset, adLockReadOnly, adCmdText
 
or try

If not (.EOF and .BOF) then
.movelast
msgbox .recordcount & " records!"
Else
msgbox "0 records!"
End If

I believe ADO has trouble determining the number of records until it's moved through the entire recordset if you use a static recordset.

Kevin
 
No. The problem is on the Distinct clause.
Sorry I posted wrong, the error happens when I do:

str = "SELECT DISTINCT * FROM Mytable WHERE ID = '" & varID & "' ORDER BY ID"

or

str = "SELECT DISTINCT FIELD2 FROM Mytable WHERE ID = '" & varID & "' ORDER BY ID"

or anything with the DISTINCT clause

Because if I do only

str = "SELECT * FROM Mytable WHERE ID = '" & varID & "' ORDER BY ID"

This will work!
But if I use DISTINCT if Mytable is empty the .RecordCOunt will return 1 instead of 0 and of course .BOF will be false!!!
This is one of those cases when I start thinking what the heck is going on here?
Because I'm all out of ideas here.

Please help me out if you can.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top