PDA

View Full Version : Recordset recordcount property



avadhutd2
01-13-2010, 05:52 AM
Hi...I need guidance about a recordset recordcount property.

I had written a function that returns whether a row exists in database or not....if it does no't exist the counter is set to 0, else it is set to 1 or more as applicable.

I am using this value in code as

If ChkRow = 0 then
' Doing some processing
End If

If ChkRow = 1 then
' Doing some processing
End If

If ChkRow > 1 then
' Doing some processing
End If


Function ChkRow As Integer
Dim SQL As String
Dim RS As ADODB.Recordset

SQL = "Select * from TableName" & & " where Primary Key = " & " ' " & "VALUE" & " ' " & ";"
' SQL can be somewhat like - Select * from TableName where TestID = "ABCD"; (here TestID is the only primary key)

Set RS = New ADODB.Recordset
RS.Open SQL, ConnectionObject, adOpenForwardOnly, adLockReadOnly
If RS.EOF Then
ChkRow = 0
Else
MsgBox RS.RecordCount
ChkRow = RS.RecordCount
End If

RS.Close
Set RS = Nothing
End Function

The problem is I am getting the recordset recordcount as -1 when there is identical record found in DB.

1. Can anyone guide me as why I am getting the RS.RecordCount as -1 instead of 1 (since the record with same primary key is already there in DB table)

2. Can there be a situation wherein we can get recordcount > 1?

Please let me know...Thanks in advance!

xld
01-13-2010, 06:08 AM
Try



RS.Open SQL, ConnectionObject, adOpenKeySet, adLockReadOnly