Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Mar 2002
    Location
    Ventura, California, USA
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Counting Records (2002)

    Hey guys need a little more help. I have a form with a continuous subform in it. On the sub form I have navigation buttons to go through the records. What I want to do is count the number of records in the table and if there are less than 2 make the navigation buttons invisible and if more make them visible.

    Any suggestions??


    Thanks Dan.

  2. #2
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Counting Records (2002)

    Here is one way you can do this. Add this sub to main form's code module:

    Public Sub HideNavButtons()

    Dim frm As Form
    Dim rst As DAO.Recordset

    Set frm = Me.NameOfSubformCtl.Form
    Set rst = frm.RecordsetClone

    frm.NavigationButtons = rst.RecordCount >= 2

    Set frm = Nothing
    Set rst = Nothing

    End Sub

    Replace "NameOfSubformCtl" with name of subform control on main form (not name of subform itself). Call this sub from main form's On Current event. In addition, call sub from subform's AfterInsert and AfterDelConfirm events. Example:

    Private Sub Form_Current()
    HideNavButtons
    End Sub

    Private Sub Form_AfterInsert()
    Me.Parent.HideNavButtons
    End Sub

    Private Sub Form_AfterDelConfirm(Status As Integer)
    Me.Parent.HideNavButtons
    End Sub

    This will hide navigations buttons when there are less than 2 records on subform. If using A2K or later you need to set a reference to DAO 3.6 Object Library.

    HTH

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Counting Records (2002)

    I'd do it this way. Create the following sub, and call it from your subform's Current event.

    Private sub DisplayNavButtons ( )
    cmdBack.visible = (me.recordsetclone.rrecordcount > 2)
    cmdForward.visible = (me.recordsetclone.recordcount > 2)
    end sub

    (oops! This is corrected version! I used .count instead of .recordcount originally!)
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •