-
Custom Record Counter
I am using a customized record counter (at least I'm trying to) and it appears to be working well for records that exist. The problem I am finding is that if a record doesn't exist, the system generates an error when I click on the tab that the subform is loaded on.
Here's the code that I'm currently using. Is there a way to account for when no record exists or maybe have the form indicate that it's new record?
Private Sub Form_Current()
Dim rst As DAO.Recordset
Dim lngCount As Long
Set rst = Me.RecordsetClone
With rst
.MoveFirst
.MoveLast
lngCount = .RecordCount
End With
Me.txtRecordNo = "Record " & Me.CurrentRecord & " of " & lngCount
End Sub
Thanks in advance.
-
I have highlighted my suggested changes:
Private Sub Form_Current()
Dim rst As DAO.Recordset
Dim lngCount As Long
Set rst = Me.RecordsetClone
With rst
If .BOF or .EOF Then 'BOF=Beggining of file, EOF=End of file
MsgBox "There are no records."
Exit Sub
End If
.MoveFirst
.MoveLast
lngCount = .RecordCount
End With
Me.txtRecordNo = "Record " & Me.CurrentRecord & " of " & lngCount
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|