Steve R.
12-02-2010, 09:59 AM
In navigating a form, I like to have the active control highlighted. Makes it easier to see where you are on the form. One of the more difficult experiences in highlighting the active control was an option group frame.
Note: I updated (5/11/2012) the code for highlighting the labels in a frame to correct an error. The label for the frame itself, had to be factored out. The error was unnoticed as the error handler simply skipped it (Resume Next).
Through the help provided by this forum I was able to develop a subroutine that would highlight the associated label of the option button when the option button was pressed. This subroutine was embedded in the form, but in upgrading my form; I have moved the subroutine into a module so that it is now form independent.
Doing so required modifying the code to pass to the subroutine the name of the form (me.form), the name of the frame in the form (Me.ActiveControl.Name), and the current value of the frame (Me.ActiveControl.Value).
Calling the subroutine from within the form.
Private Sub Frame50_Enter()
Call Enter_Frame(Me.Name, Me.ActiveControl.Name, Me.ActiveControl.Value)
End Sub
Private Sub Frame50_Click()
Call Enter_Frame(Me.Name, Me.ActiveControl.Value, Me.ActiveControl.Name)
End Sub
Private Sub Frame50_Exit(Cancel As Integer)
Call Exit_Frame(Me.Name,Me.ActiveControl.Name)
End Sub
Code located in the module section.
strFormName: refers to the name of the form.
strControlName: refers to the name of the frame.
intControlValue: is the option value of the frame.
Redclr: is a global long integer that is user defined, in this case "red".
Public Sub Enter_Frame(strFormName As String, strControlName As String, intControlValue As Integer)
For Each CTRL In Forms(strFormName).Controls(strControlName).Contro ls
If CTRL.ControlType = acLabel Then
If CTRL.Parent.ControlType = acOptionButton Then
If CTRL.Parent.OptionValue = intControlValue Then
CTRL.BorderColor = Redclr
CTRL.BorderStyle = 1 'Solid Line
Else
CTRL.BorderStyle = 0 'Transparent
End If
End If
End If
Next CTRL
End Sub
Public Sub Exit_Frame(strFormName As String, strControlName As String)
For Each CTRL In Forms(strFormName).Controls(strControlName).Contro ls
If CTRL.ControlType = acLabel Then CTRL.BorderStyle = 0 'Transparent
Next CTRL
End Sub
To facilitate the use of the code above, you will also need something like the code below so that the borders become easily observable when made visible:
Private Sub Form_Load()
For Each CTRL In Me.Controls
If CTRL.ControlType = acLabel Or CTRL.ControlType = acTextBox Then
CTRL.BorderStyle = 1 'Solid Line
CTRL.BorderWidth = 4
End If
Next CTRL
End Sub
Note: I updated (5/11/2012) the code for highlighting the labels in a frame to correct an error. The label for the frame itself, had to be factored out. The error was unnoticed as the error handler simply skipped it (Resume Next).
Through the help provided by this forum I was able to develop a subroutine that would highlight the associated label of the option button when the option button was pressed. This subroutine was embedded in the form, but in upgrading my form; I have moved the subroutine into a module so that it is now form independent.
Doing so required modifying the code to pass to the subroutine the name of the form (me.form), the name of the frame in the form (Me.ActiveControl.Name), and the current value of the frame (Me.ActiveControl.Value).
Calling the subroutine from within the form.
Private Sub Frame50_Enter()
Call Enter_Frame(Me.Name, Me.ActiveControl.Name, Me.ActiveControl.Value)
End Sub
Private Sub Frame50_Click()
Call Enter_Frame(Me.Name, Me.ActiveControl.Value, Me.ActiveControl.Name)
End Sub
Private Sub Frame50_Exit(Cancel As Integer)
Call Exit_Frame(Me.Name,Me.ActiveControl.Name)
End Sub
Code located in the module section.
strFormName: refers to the name of the form.
strControlName: refers to the name of the frame.
intControlValue: is the option value of the frame.
Redclr: is a global long integer that is user defined, in this case "red".
Public Sub Enter_Frame(strFormName As String, strControlName As String, intControlValue As Integer)
For Each CTRL In Forms(strFormName).Controls(strControlName).Contro ls
If CTRL.ControlType = acLabel Then
If CTRL.Parent.ControlType = acOptionButton Then
If CTRL.Parent.OptionValue = intControlValue Then
CTRL.BorderColor = Redclr
CTRL.BorderStyle = 1 'Solid Line
Else
CTRL.BorderStyle = 0 'Transparent
End If
End If
End If
Next CTRL
End Sub
Public Sub Exit_Frame(strFormName As String, strControlName As String)
For Each CTRL In Forms(strFormName).Controls(strControlName).Contro ls
If CTRL.ControlType = acLabel Then CTRL.BorderStyle = 0 'Transparent
Next CTRL
End Sub
To facilitate the use of the code above, you will also need something like the code below so that the borders become easily observable when made visible:
Private Sub Form_Load()
For Each CTRL In Me.Controls
If CTRL.ControlType = acLabel Or CTRL.ControlType = acTextBox Then
CTRL.BorderStyle = 1 'Solid Line
CTRL.BorderWidth = 4
End If
Next CTRL
End Sub