• Counting Records (2002)

    Author
    Topic
    #381189

    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.

    Viewing 1 reply thread
    Author
    Replies
    • #641316

      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

    • #641348

      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!)

    Viewing 1 reply thread
    Reply To: Counting Records (2002)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: