We're now going to add the code that will manipulate the buttons on our control.
Add a new private sub routine to your control and call it navigateButtons
. Add the parameter buttonString
as type String
. This buttonString
will simply be a string of 0's and 1's. Depending on the position of the 0 or 1, the appropriate button will be enabled or disabled. The brains of this operation was in the updateButtons
routine that we just looked at. It determines which buttons should be enabled or disabled, builds the string, and sends it to navigateButtons
to execute. Enter the code below:
Private Sub navigateButtons(buttonString As String)
''--------------------------------------------------
''-- This routine handles setting the enabled --
''-- to true / false on the buttons. --
''-------------------------------------------------
''-- A string of 0101 passed. If 0, disabled --
''-------------------------------------------------
Dim indx As Integer
buttonString = Trim$(buttonString)
For indx = 1 To Len(buttonString)
If (Mid$(buttonString, indx, 1) = "1") Then
cmdButton(indx - 1).Enabled = True
Else
cmdButton(indx - 1).Enabled = False
End If
Next
DoEvents
End Sub
Again, nothing out of the ordinary here. We have seen this before as well in our data control class.
So, if our control doesn't know in advance the names of the bound controls that will be used with it, how can it refer to them to lock and unlock them during editing? Here's how: