InitialiseEvents problem Plz Help (1 Viewer)

ahmedjamalaboelez

Ahmed J. Aboelez
Local time
Yesterday, 21:17
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
 

JANR

Registered User.
Local time
Today, 06:17
Joined
Jan 21, 2009
Messages
1,623
Try and call the Function in the Open event of your subform also, it should work.

The subform will load before your mainform and be dumped in your subformcontrol on your main form.

JanR
 

Users who are viewing this thread

Top Bottom