ahmedjamalaboelez
Ahmed J. Aboelez
- Local time
- Today, 08:25
- Joined
- Feb 25, 2015
- Messages
- 79
Private Sub Form_Open(Cancel As Integer)
InitialiseEvents Me
End Sub
Quesion !
when Run this Function on form all form ctrls affected but not Subform ctrls plz help ???????
what Could Change to apply it on Subform Ctrls ?????
Public Function InitialiseEvents(frm As Access.Form)
Dim ctl As Control
For Each ctl In frm.Controls
With ctl
If .ControlType = acComboBox Then
.OnGotFocus = "=HandleFocus('" & frm.Name & "', '" & .Name & "', 'Got')"
.OnLostFocus = "=HandleFocus('" & frm.Name & "', '" & .Name & "', 'Lost')"
End If
End With
Next ctl
End Function
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
InitialiseEvents Me
End Sub
Quesion !
when Run this Function on form all form ctrls affected but not Subform ctrls plz help ???????
what Could Change to apply it on Subform Ctrls ?????
Public Function InitialiseEvents(frm As Access.Form)
Dim ctl As Control
For Each ctl In frm.Controls
With ctl
If .ControlType = acComboBox Then
.OnGotFocus = "=HandleFocus('" & frm.Name & "', '" & .Name & "', 'Got')"
.OnLostFocus = "=HandleFocus('" & frm.Name & "', '" & .Name & "', 'Lost')"
End If
End With
Next ctl
End Function
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