ahmedjamalaboelez
Ahmed J. Aboelez
- Local time
- Today, 00:13
- Joined
- Feb 25, 2015
- Messages
- 79
Hi , Good day everyone
I'm Calling following code in Form Open Event So Code set Got and Lost Focus Event For Each Control in the form ,So Each Control On Got Focus Got Bold Font And Reg Border Color , This Code Run in Main Form with no issues, But its not Run in Sub Form Open Event, So Please Any Advice to Run This In Sub Form Too
This Code I Found Many Years Before , While I'm Searching Change Format of form Controls
Click Here To See Original Thread
Thank You So Much ,
I'm Calling following code in Form Open Event So Code set Got and Lost Focus Event For Each Control in the form ,So Each Control On Got Focus Got Bold Font And Reg Border Color , This Code Run in Main Form with no issues, But its not Run in Sub Form Open Event, So Please Any Advice to Run This In Sub Form Too
This Code I Found Many Years Before , While I'm Searching Change Format of form Controls
Click Here To See Original Thread
Code:
Option Explicit
Option Compare Text
Public Sub InitialiseEvents(ByRef frmThisForm As Form)
Dim ctl As Control
On Error Resume Next
For Each ctl In frmThisForm
ctl.OnGotFocus = "=HandleFocus('" & frmThisForm.Name & "', '" & ctl.Name & "', 'Got')"
ctl.OnLostFocus = "=HandleFocus('" & frmThisForm.Name & "', '" & ctl.Name & "', 'Lost')"
Next ctl
Err.Clear
End Sub
Public Function HandleFocus(ByVal strFormName As String, _
ByVal strControlName As String, _
ByVal strChange As String)
Static lngForeColour As Long
Static lngFontWeight As Long
Static lngBorderStyle As Long
Static lngBorderColour As Long
Static lngBackStyle As Long
Static lngBackColour As Long
On Error Resume Next
With Forms(strFormName)(strControlName)
Select Case strChange
Case "Got"
' Save current configuration.
lngForeColour = .ForeColor
lngFontWeight = .FontWeight
lngBorderStyle = .BorderStyle
lngBorderColour = .BorderColor
lngBackStyle = .BackStyle
lngBackColour = .BackColor
' Set required configuration.
.ForeColor = vbBlue
.FontWeight = 700
.BorderStyle = 1
.BorderColor = vbRed
.BackStyle = 1
.BackColor = vbYellow
Case "Lost"
' Restore saved configuration.
.ForeColor = lngForeColour
.FontWeight = lngFontWeight
.BorderStyle = lngBorderStyle
.BorderColor = lngBorderColour
.BackStyle = lngBackStyle
.BackColor = lngBackColour
End Select
End With
Err.Clear
End Function