rs.RecordCount

M

Maracay

Hi Guys

I need to know how many records I have in my record source that why I am
using rs.RecordCount after my sql statement, if there are no records I got
zero that is OK, but if I got more than 1 record I got a 1, what I want to
know is the exact number of records in my record source.

Thanks
 
J

Jon Lewis

You need to move to the end of the recordset to 'populate' the RecordCount
property. Try:

rs.MoveLast
rs.MoveFirst
rs.RecordCount 'should then return the correct count

Jon
 
D

Daniel Pineault

You have to force the recordset to go to the last record before getting your
recordcount to ensure a proper count. You'd have to do something like:

If rs.RecordCount = 0 then
MsgBox "You have no Records."
Else
rs.MoveLast
MsgBox "You have " & rs.RecordCount & " Records."
End if


--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.
 
M

Maracay

Hi Guys,

for dome reason nothings works, this is my record source

Dim NumRec As Integer
Dim rs As Recordset
Dim db As Database
Set db = CurrentDb

Set rs = db.OpenRecordset( _
"select DocketNumber " & _
"from tblDDocket " & _
"where DocketNumber = " & Me.TextDockNumb & " and
DocketSequence = " & Me.TextSequenceNumber)

after this I placed both options but nothing works.

Thanks
 
D

Daniel Pineault

Assuming your SQL Statement is good, then you'd do

Dim NumRec As Integer
Dim rs As Recordset
Dim db As Database
Set db = CurrentDb

Set rs = db.OpenRecordset( _
"select DocketNumber " & _
"from tblDDocket " & _
"where DocketNumber = " & Me.TextDockNumb & " and
DocketSequence = " & Me.TextSequenceNumber)

If rs.RecordCount = 0 Then
MsgBox "There are no records!"
Else
rs.MoveLast
MsgBox "There are " & Me.RecordCount & " records!"
End If

rs.Close
Set rs = Nothing
Set db = Nothing



Have you tested that you SQL statement works?!
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.
 

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