L
Lee Taylor-Vaughan
Hello group,
I have the following code that is giving me error number 91. (i am trying to
count records in a list box with this code); I have the read the ms access
help on it, but it doesnt make sense to me. I have tried adding a break
point and hovering the mouse of ther (me.list74.rowsource) and intellesense
gives the sql statement (or part of it i.e. "SELECT firstname, last
name ......."). (i am wondering how long an SQL statement can be for its
declaration?)
can you please take a quick peek at this code and advise why it is not
working? as I have gotten tired of banging my head against the wall with it
and feel it is time to ask for some help.
Private Sub CountRecords()
On Error GoTo Err_Clear_Click
Dim lngCount As Integer
Dim dbCurrent As DAO.Database
Dim rsData As DAO.Recordset
Set dbCurrent = CurrentDb
Set rsData = Nothing
Set rsData = CurrentDb.OpenRecordset(Me.List74.RowSource)
lngCount = 0
rsData.MoveLast
rsData.MoveFirst
Do While rsData.EOF = False
rsData.MoveNext
lngCount = lngCount + 1
Loop
Exit_Clear_Click:
Forms!frmUserSearch.Caption = "User Search: Total Records: " &
Nz(lngCount)
Exit Sub
Err_Clear_Click:
' Debug.Print rsData
Select Case Err.Number
Case Is = 3021 'no records in set
MsgBox "There are no Users for your selection", vbCritical, "No
Records to display"
Me.List74.RowSource = ""
Forms!frmUserSearch.Caption = "User Search: Total Records: " &
Nz(lngCount)
Exit Sub
Case 3078 'no records in database
MsgBox "There are no records entered into the database.",
vbInformation, "No Data to display"
Forms!frmUserSearch.Caption = "User Search: Total Records: " &
Nz(lngCount)
Exit Sub
Case Else
MsgBox Err.Number & ": " & Err.Description, vbCritical, "Error
Message, gulp...!"
Forms!frmUserSearch.Caption = "User Search: Total Records: " &
Nz(lngCount)
Exit Sub
End Select
Set dbCurrent = Nothing
Set rsData = Nothing
End Sub
thanks
Lee
I have the following code that is giving me error number 91. (i am trying to
count records in a list box with this code); I have the read the ms access
help on it, but it doesnt make sense to me. I have tried adding a break
point and hovering the mouse of ther (me.list74.rowsource) and intellesense
gives the sql statement (or part of it i.e. "SELECT firstname, last
name ......."). (i am wondering how long an SQL statement can be for its
declaration?)
can you please take a quick peek at this code and advise why it is not
working? as I have gotten tired of banging my head against the wall with it
and feel it is time to ask for some help.
Private Sub CountRecords()
On Error GoTo Err_Clear_Click
Dim lngCount As Integer
Dim dbCurrent As DAO.Database
Dim rsData As DAO.Recordset
Set dbCurrent = CurrentDb
Set rsData = Nothing
Set rsData = CurrentDb.OpenRecordset(Me.List74.RowSource)
lngCount = 0
rsData.MoveLast
rsData.MoveFirst
Do While rsData.EOF = False
rsData.MoveNext
lngCount = lngCount + 1
Loop
Exit_Clear_Click:
Forms!frmUserSearch.Caption = "User Search: Total Records: " &
Nz(lngCount)
Exit Sub
Err_Clear_Click:
' Debug.Print rsData
Select Case Err.Number
Case Is = 3021 'no records in set
MsgBox "There are no Users for your selection", vbCritical, "No
Records to display"
Me.List74.RowSource = ""
Forms!frmUserSearch.Caption = "User Search: Total Records: " &
Nz(lngCount)
Exit Sub
Case 3078 'no records in database
MsgBox "There are no records entered into the database.",
vbInformation, "No Data to display"
Forms!frmUserSearch.Caption = "User Search: Total Records: " &
Nz(lngCount)
Exit Sub
Case Else
MsgBox Err.Number & ": " & Err.Description, vbCritical, "Error
Message, gulp...!"
Forms!frmUserSearch.Caption = "User Search: Total Records: " &
Nz(lngCount)
Exit Sub
End Select
Set dbCurrent = Nothing
Set rsData = Nothing
End Sub
thanks
Lee