访问帮助:
一个表单可以获取焦点只有一个窗体上的所有 可见控件 残疾,或有没有控制 的表格。
您可能想尝试激活。
编辑评论重新
我可以看到你在做什么似乎想的唯一方法是使用的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
这是非常,非常粗糙,但它给你有什么可以搞砸的。
尝试使用窗体的激活事件? – 2011-01-11 16:09:45
@彼得勋爵试着使用Activate,如果你能看到我的评论如下。 – noelmcg 2011-01-11 16:43:49