Why doesn't .GetFocus get the message?

MyTech

Access VBA
Local time
Today, 03:53
Joined
Jun 10, 2010
Messages
108
Why doesn't .SetFocus get the message?

Can anybody tell me why .SetFocus does not work in this code in a continuous form?

Code:
Private Sub ConnectIdentify_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
        Dim strFilter$
        strFilter = Screen.ActiveControl.Name & "='" & Screen.ActiveControl.Value & "'"
        If Me.FilterOn = False Then
            Me.Filter = strFilter
            Me.FilterOn = True
        Else: Me.FilterOn = False
        End If
    End If
    ConnectIdentify.SetFocus
End Sub

When the filter is applied (if FilterOn was False) then the focus stays on the current control, regardless of my 'ConnectIdentify.SetFocus' code.

But when the filter is removed (if FilterOn was True), then the focus goes to the next control even if I put in the 'ConnectIdentify.SetFocus' code.


When I put the SetFocus in a DIFFERENT control, it DOES follow and gives focus for the required control.

Code:
Private Sub ConnectType_LostFocus()
ConnectIdentify.SetFocus
End Sub


???
 
Last edited:
Re: Why doesn't .SetFocus get the message?

I got a way to workaround.

I added "KeyCode = 0" to the code, so the focus is not going out of the control.
I would like though if somebody could explain to me the reason why the 'enter' button (13) doesn't follow a SetFocus command.

Here is the code with the workaround:
Code:
Private Sub ConnectIdentify_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
        Dim strFilter$
        strFilter = Screen.ActiveControl.Name & "='" & Screen.ActiveControl.Value & "'"
        If Me.FilterOn = False Then
            Me.Filter = strFilter
            Me.FilterOn = True
        Else
        KeyCode = 0
        Me.FilterOn = False
        End If
    End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom