I have a single Form with a Tab Control with multiple pages, and over 200 controls, mostly Textbox and ComboBox. I have some code that is fired by the KeyPress event of the Form (KeyPreview = True) that loops through controls, changing the BackColor to white except for the control with the focus, which has a BackColor of yellow. This all works fine.
Problem is the end users often move around the Form using the mouse and clicking into controls they want to update, so I am trying to find a way of firing the code from a Form MouseDown or Click event. Obviously I could put a reference to the Sub Routine in each individual control to call it on Click, but that means repeating it over 200 times. There must be a simpler way!
Here is the code that works on Form KeyPress event (variable iTabPage is the Tab page value, so I only loop through the Page with the focus)
Problem is the end users often move around the Form using the mouse and clicking into controls they want to update, so I am trying to find a way of firing the code from a Form MouseDown or Click event. Obviously I could put a reference to the Sub Routine in each individual control to call it on Click, but that means repeating it over 200 times. There must be a simpler way!
Here is the code that works on Form KeyPress event (variable iTabPage is the Tab page value, so I only loop through the Page with the focus)
Code:
Dim Ctl As Control
For Each Ctl In Me![TabCtl].Pages([B]iTabPage[/B]).Controls
If Ctl.ControlType = acTextBox Or Ctl.ControlType = acComboBox Then
Ctl.BackColor = IIf(Ctl.Name = Screen.ActiveControl.Name, 8454143, 16777215)
End If
Next
Comment