This thread has a solution to add onClick
events to controls dynamically. As it turns out, although you can add your own event, you can't add your own event AND have your normal control_click()
event, too. It's just that you can set it at runtime via code, and it can be named whatever you want (as long as it is a function).
This sort of answers my question: you CAN add an onclick
event to every control dynamically without having to create them in the gui. Here is the syntax which you can put in form_onload
if you like:
with Me.myControl
Me.myControl.OnEnter = "=SomeFunction()"
end with
And here's how to add an .OnEnter
event to every textbox control (just call the SetReportControls
method from form_open
:
Private Sub SetReportControls()
Dim ctrl As Control
For Each ctrl In Me.Controls
With ctrl
If TypeOf ctrl Is Access.TextBox Then
.OnEnter = "=ReportControl(false)"
End If
End With
Next
End Sub
Private Function ReportControl(Cancel As Integer)
msgbox Screen.ActiveControl.Name
End Function