Export (0) Print
Expand All

Updating the User Interface

Visual Studio 6.0

Just like our data class, this routine is responsible for enabling/disabling the command buttons. We have been talking about it, so let's take a closer look and code for this feature.

Try It Out - Coding the updateButtons Subroutine

1.  Add a private subroutine called updateButtons and add an Optional variant parameter called bLockem:

Private Sub updateButtons(Optional bLockem As Variant)

'-------------------------------------
'Position   Button
'   0       move first
'   1       move previous
'   2       move next
'   3       move last
'   4       add a new record
'   5       edit the current record
'   6       save the current record
'   7       delete the current record
'   8       undo any current changes
'--------------------------------------
'

'Either we are Editing / Adding or we are not
If (editStatus = nowEditing) Or (editStatus = nowadding) Then
   Call lockTheControls(False)
   navigateButtons ("000000101")
Else
   If (adoRecordset.RecordCount > 2) Then
      If (adoRecordset.BOF) Or _
         (adoRecordset.AbsolutePosition = 1) Then
           navigateButtons ("001111010")
       ElseIf (adoRecordset.EOF) Or _
          (adoRecordset.AbsolutePosition = lTotalRecords) Then
             navigateButtons ("110011010")
       Else
             navigateButtons ("111111010")
       End If
   ElseIf (adoRecordset.RecordCount > 0) Then
       navigateButtons ("000011010")
   Else
       navigateButtons ("000010000")
   End If
     
   If (Not IsMissing(bLockem)) Then
      lockTheControls (bLockem)
   End If
        
End If

End Sub

How It Works

This should look familiar – it mirrors what we did when we were building our data class. This routine is called from the cmdButton_Click routine. Whenever a button is clicked, this routine is called and is responsible for figuring out which buttons should be enabled or disabled. It checks the editStatus and record count. Once it knows the current state of the program, our handy routine calls the navigateButtons helper sub that actually does the work of enabling or disabling the appropriate buttons.

And if the state of the program is nowStatic (not adding or editing a record), then the optional parameter of bLockem is checked. If it is there, the controls either get locked or unlocked.

Next, we'll take a peek at the navigateButtons sub that does the enabling and disabling for us.

© 1998 by Wrox Press. All rights reserved.

Show:
© 2014 Microsoft