>if you are use rs.open s,Conn, adOpenForwardOnly, >adLockReadOnly then avoid the statement :
>If rs.BOF = False Or rs.EOF = False then
May I ask why not?
The BOF and EOF statement should be used.
The rest of your code is also incorrect and will not work properly.
An adOpenForwardOnly will always return -1, and so your code will always return "file is empty".
The only time this will work is if you are using a client cursor (not the case above), and then it is not a adOpenForwardOnly cursor anymore (no matter if you wanted one by setting this cursor type) but changes to a Static cursor instead. A Client side cursor here is always Static to the source, but updatable to the Client Cursor.
Then the adOpenForwardOnly is a useless/meaningless argument.
BlueByte:
>rs.recordCount is returning -1
That's because of the adOpenForwardOnly cursor.
You have 3 choices:
1. You could change the cursor type to Static or Keyset.
You may need to then issue a MoveLast and MoveFirst to make sure the count is accurate.
2. Or, just use a Client cursor (rs.CursorLocation = adUseClient) and then the record count should be correct - However, all of the records will be pulled in locally.
May not be what you want, actually defeating the purpose of a ForwardOnly cursor.
3. Or, if it needs to be a adOpenForwardOnly server cursor, you will need to issue a second query to count the records. This is done effeciently by using:
Dim lRecordCount As Long
If Not (rs.BOF and rs.EOF) Then
'(We now know there are records in the rs, but do not know how many)
set rs2 = conn.Execute "SELECT COUNT(*) FROM SomeTable",,adCmdText
lRecordCount = rs2.Collect(0)
rs2.Close
Else
'No records
End If
set rs2 = nothing
Now we have an approx. record count for a Forward Only Cursor.
I say "approx." because one or more records could have been added by some other user(s) in the time between the first rs and the second rs were opened.
Therefore, always use a EOF check if you are using the record count for anything other than information purposes.
(You could also use a SP with a return count).