Results 1 to 2 of 2

Thread: Custom Record Counter

  1. #1
    Join Date
    Jun 2004
    Location
    Edmonton Alberta
    Posts
    19

    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.

  2. #2
    Join Date
    May 2006
    Posts
    407
    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
  •