Custom Navigation Controls Odd Behavior

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jalbright1957
    New Member
    • Mar 2016
    • 25

    Custom Navigation Controls Odd Behavior

    On the form in question i have records from 5 related tables. In the footer of the form I have navigation controls (default navigation controls are turned off). When the form is launched, the navigation controls always appear disabled (grayed out). If I debug the code and put a break point where it enters the if conditions for the On Current event of the form and step through it, the navigation controls work fine. I do have a combobox on the form where the user can page through the records or type in characters of a customer they wish to view. Once a record is selected, the navigation controls work fine. Ideas?
    Code:
    On Error Resume Next
          If Me.CurrentRecord = 1 Then
             Me.cmdPrevious.Enabled = False
             Me.cmdFirst.Enabled = False
          Else
             Me.cmdPrevious.Enabled = True
             Me.cmdFirst.Enabled = True
          End If
          If Me.CurrentRecord >= Me.Recordset.RecordCount Then
             Me.cmdNext.Enabled = False
             Me.cmdLast.Enabled = False
          Else
             Me.cmdNext.Enabled = True
             Me.cmdLast.Enabled = True
          End If
  • PhilOfWalton
    Recognized Expert Top Contributor
    • Mar 2016
    • 1430

    #2
    I use similar code, but hide the buttons again in the On Currant

    Code:
        If Me.CurrentRecord = 1 Then
            CmdPrevious.Visible = False
        Else
            CmdPrevious.Visible = True
        End If
        
        If Me.CurrentRecord = Me.Recordset.RecordCount Then
            Cmdnext.Visible = False
        Else
            Cmdnext.Visible = True
        End If
    Can't see why your method won't work as there is very little difference. However on opening my form the next button is visible.

    Phil

    Comment

    • jalbright1957
      New Member
      • Mar 2016
      • 25

      #3
      I can't explain what may be causing this. I thought it might be due to it taking too long to read records and report back but the table doesn't have very many records.

      Comment

      • jalbright1957
        New Member
        • Mar 2016
        • 25

        #4
        A bit of an update: If I enable Navigation Buttons in the form properties, my custom navigation buttons work as designed. Disabke Navigation Buttons in the form properties and my custom buttons fail when launching the form. Obviously I am missing something important here.

        Comment

        • jforbes
          Recognized Expert Top Contributor
          • Aug 2014
          • 1107

          #5
          Two things I can think of:
          • Comment out the Error Handling and see if you get an error. Access can get odd about Focus when disabling controls.
          • Put this code into your OnCurrent code: Debug.Print "CurrentRec ord is " & Me.CurrentRecor d & " out of " & Me.Recordset.Re cordCount Then you can verify a little more of what is going on in the OnCurrent. You may want to put a debug.print for each branch of the IF statements.

          Comment

          • jalbright1957
            New Member
            • Mar 2016
            • 25

            #6
            I didn't get an error by commenting out the error handling. On the first entry into the event, debug.print shows 1 out of 1 records instead of showing 1 out of 10 records (currently there are 10 records in the table.) As long as the breakpoint at the entry of the event is active, the controls work as planned. Remove the breakpoint and it doesn't read the table.

            In case this sheds a bit of light into what I'm doing. The tables being used on the form consist of a company table, city table, state table, company contact table and a company classification table. The company contact table is the many side of the company table. The company table is the many side of the city, state and classification tables. The record source for the form is a query with the three masters and the company table. The company contact table is in a subform by itself, has the parent and child fields set and is the only subform on the main form.

            Comment

            • jforbes
              Recognized Expert Top Contributor
              • Aug 2014
              • 1107

              #7
              This actually makes sense. If it's on Record #1 and it thinks there are only 1 record(s), then
              Code:
              If Me.CurrentRecord >= Me.Recordset.RecordCount Then
              will evaluate to True, disabling your fields.

              You could try something like the following:
              Code:
              On Error Resume Next
              [iCODE]Dim oClone As Recordset[/iCODE]    
              [iCODE]Set oClone = Me.RecordsetClone[/iCODE]
              [iCODE]oClone.MoveLast[/iCODE]
              
              If Me.CurrentRecord = 1 Then
                  Me.cmdPrevious.Enabled = False
                  Me.cmdFirst.Enabled = False
              Else
                  Me.cmdPrevious.Enabled = True
                  Me.cmdFirst.Enabled = True
              End If
              If Me.CurrentRecord >= [iCODE]oClone.RecordCount[/iCODE] Then
                  Me.cmdNext.Enabled = False
                  Me.cmdLast.Enabled = False
              Else
                  Me.cmdNext.Enabled = True
                  Me.cmdLast.Enabled = True
              End If
              This should make a copy of the Form's RecordSet and then move to it's end, somewhat forcing it to load completely, at least load completely into the Clone.

              Lastly, this line will act differently depending on if you can Add records to your Form:
              Code:
              If Me.CurrentRecord >= Me.Recordset.RecordCount Then
              The .CurrentRecord for the New Record will be the RecordCount + 1.
              You may want to flip flop the If Statement:
              Code:
              If Me.CurrentRecord < oClone.RecordCount Then
              -or when new records can be added- 
              If Me.CurrentRecord <= oClone.RecordCount Then
                  Me.cmdNext.Enabled = True
                  Me.cmdLast.Enabled = True
              Else
                  Me.cmdNext.Enabled = False
                  Me.cmdLast.Enabled = False
              End If

              Comment

              • jalbright1957
                New Member
                • Mar 2016
                • 25

                #8
                Thanks Jforbes... That took care of the problem. Appreciate the solution.

                Comment

                Working...