gpt4 book ai didi

ms-access - Forms GotFocus 事件似乎没有触发

转载 作者:行者123 更新时间:2023-12-02 04:11:54 24 4
gpt4 key购买 nike

当特定表单打开时,当用户将焦点返回到 Access 应用程序时,我试图调用一个事件。以下事件似乎根本没有发生。

Private Sub Form_GotFocus()
Call crtListDirectory
End Sub

是否有人对我如何触发此事件以及 Form_GotFocus 事件何时/如何实际触发有任何想法。

提前感谢您的帮助

诺埃尔

最佳答案

Access 帮助:

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



您可能想尝试激活。

编辑重新评论

我能看到做你想做的事情的唯一方法是使用 API,这有点困惑。为了演示这一点,您将需要一个带有两个控件 Text0 和 Text2(这些是默认名称)的表单。将 Timer Interval 设置为合适的值,例如 2000,并将 Timer Event 设置为:
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

这一切都非常非常粗糙,但它会给你一些麻烦。

关于ms-access - Forms GotFocus 事件似乎没有触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4659457/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com