Wappervliegje
Registered User.
- Local time
 - Today, 15:04
 
- Joined
 - Nov 11, 2014
 
- Messages
 - 23
 
Dear people,
I'm trying to find out how I can get GotFocus and LostFocus of all comboboxes. See below the three codes (code 1, 2 and 3) that I've change from an example from the internet. But the problem is that the function "InitialiseEvents" is not running in these comboboxes. If I try the code 4 as an example, the function "InitialiseEvents" is running perfectly. I don't understand why I can't get GotFocus and LostFocus? I think I'm really forgotten one thing, but I don't know anymore... Please, can you help me?
You can to see two attachments:
Afbeelding1: The codes 1, 2 and 3 are running.
Afbeelding2: The codes 1, 2 and 4 are running.
Code 1:
	
	
	
		
 Code 2:
	
	
	
		
 Code 3:
	
	
	
		
 Code 4:
	
	
	
		
 I'm trying to find out how I can get GotFocus and LostFocus of all comboboxes. See below the three codes (code 1, 2 and 3) that I've change from an example from the internet. But the problem is that the function "InitialiseEvents" is not running in these comboboxes. If I try the code 4 as an example, the function "InitialiseEvents" is running perfectly. I don't understand why I can't get GotFocus and LostFocus? I think I'm really forgotten one thing, but I don't know anymore... Please, can you help me?
You can to see two attachments:
Afbeelding1: The codes 1, 2 and 3 are running.
Afbeelding2: The codes 1, 2 and 4 are running.
Code 1:
		Code:
	
	
	Private Sub Form_Open(Cancel As Integer)
    InitialiseEvents Me
End Sub
	
		Code:
	
	
	 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
	
		Code:
	
	
	 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
	
		Code:
	
	
	 Public Function InitialiseEvents(frm As Access.Form)
Dim ctl As Control
    For Each ctl In frm.Controls
        With ctl
            If .ControlType = acComboBox Then
                .Enabled = False
            End If
        End With
    Next ctl
End Function