RecordCount clarification

T

TeeSee

Using DAO. Access 2003
Having based a recordset on a combo box value I am now trying to
establish the RecordCount at any given time. While I understand that
DAO requires that you .MoveLast then (I'm quite happy to .MoveFirst at
the moment) to determine the RecordCount. Does access evaluate a zero
RecordCount immediately without the need to . .MoveLast/.Movefirst.
Further ..... if there are "no records" are we at EOF?

With rst
..MoveLast
..MoveFirst
End With
If rst.RecordCount = 0 Then
MsgBox "no records"
ElseIf rst.RecordCount > 0 Then
For Each ctl In [Forms]![frmProjectListBycompany].Controls
If ctl.ControlType = acTextBox Then
ctl.Visible = True
End If
Next
End If

If there are no records I get Run time error 3021 " no record"

Comments/feedback really appreciated. Thanks
 
M

Marshall Barton

TeeSee said:
Using DAO. Access 2003
Having based a recordset on a combo box value I am now trying to
establish the RecordCount at any given time. While I understand that
DAO requires that you .MoveLast then (I'm quite happy to .MoveFirst at
the moment) to determine the RecordCount. Does access evaluate a zero
RecordCount immediately without the need to . .MoveLast/.Movefirst.
Further ..... if there are "no records" are we at EOF?

With rst
.MoveLast
.MoveFirst
End With
If rst.RecordCount = 0 Then
MsgBox "no records"
ElseIf rst.RecordCount > 0 Then
For Each ctl In [Forms]![frmProjectListBycompany].Controls
If ctl.ControlType = acTextBox Then
ctl.Visible = True
End If
Next
End If

If there are no records I get Run time error 3021 " no record"


When there are no records, there is no first or last record
to move to. The record count will be 0 only when there are
no records so your code do not need to know how many records
are in the record set.

If rst.RecordCount = 0 Then
MsgBox "no records"
Else
For Each ctl In Forms!frmProjectListBycompany.Controls
If ctl.ControlType = acTextBox Then
ctl.Visible = True
End If
Next
End If

And, if RecordCount = 0, both EOF and BOF will be True
 
T

TeeSee

TeeSee said:
Using DAO. Access 2003
Having based a recordset on a combo box value I am now trying to
establish the RecordCount at any given time. While I understand that
DAO requires that you .MoveLast then (I'm quite happy to .MoveFirst at
the moment) to determine the RecordCount. Does access evaluate a zero
RecordCount immediately without the need to . .MoveLast/.Movefirst.
Further ..... if there are "no records" are we at EOF?
With rst
.MoveLast
.MoveFirst
End With
If rst.RecordCount = 0 Then
MsgBox "no records"
ElseIf rst.RecordCount > 0 Then
For Each ctl In [Forms]![frmProjectListBycompany].Controls
   If ctl.ControlType = acTextBox Then
   ctl.Visible = True
   End If
   Next
   End If
If there are no records I get Run time error 3021 " no record"

When there are no records, there is no first or last record
to move to.  The record count will be 0 only when there are
no records so your code do not need to know how many records
are in the record set.

        If rst.RecordCount = 0 Then
                MsgBox "no records"
        Else
                For Each ctl In Forms!frmProjectListBycompany.Controls
                        If ctl.ControlType = acTextBox Then
                                ctl.Visible = True
                End If
                Next
        End If

And, if RecordCount = 0, both EOF and BOF will be True

--
Marsh
MVP [MS Access]- Hide quoted text -

- Show quoted text -

Thank you Marshall!
 

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

Similar Threads


Top