GotFocus event forms do not seem to fire

I am trying to raise an event when the user returns focus to the Access application when a specific form is open. The following event does not seem to fire.

Private Sub Form_GotFocus()
    Call crtListDirectory
End Sub 

Does any authority have any ideas on how I can fire this event, and when / how the Form_GotFocus event occurs.

in advance for any help

Noel

+3
source share
1 answer

Access Help:

A form can receive focus only if all visible controls on the form are disabled or there are no controls on the form.

You might like to try Activate.

EDIT re Comments

, , , , , - API, . , Text0 Text2 ( ). - , 2000, :

Private Sub Form_Timer()
Dim lngWin As Long
Dim s As String

    'This is just a counter to show that the code is running
    Me.Text2 = Nz(Me.Text2, 0) + 1

    'API
    lngWin = GetActiveWindow()
    s = GetWinName(lngWin)

    If s = "Microsoft Access" Then
        If Me.Text0 = "Lost Focus" Then
            Me.Text0 = "Focus returned"
        End If
    Else
        Me.Text0 = "Lost Focus"
    End If

End Sub

:

Option Compare Database

Declare Function GetActiveWindow Lib "user32" () As Integer
Declare Function GetWindowText Lib "user32.dll" Alias _
"GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As _
String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias _
"GetWindowTextLengthA" (ByVal hwnd As Long) As Long

Function GetWinName(hw As Long)
    Dim lngText As Long ' receives length of text of title bar
    Dim strWinName As String ' receives the text of the title bar
    Dim lngWinText As Long ' receives the length of the returned string

    lngText = GetWindowTextLength(hw)
    strWinName = Space(lngText + 1)
    lngWinText = GetWindowText(hw, strWinName, lngText + 1)
    strWinName = Left(strWinName, lngWinText)
    GetWinName = strWinName
End Function

, , -, .

+1

Source: https://habr.com/ru/post/1784761/


All Articles