【发布时间】:2017-07-04 14:31:10
【问题描述】:
如何识别控件对象(例如 acTextBox)是否是 VBA 中页面集合的成员?
当一个控件对象有焦点时,会调用一个函数来根据所使用的键的类型将焦点移动到下一个 control.tabindex。我设法用 Sendkeys "{TAB}" 做到了这一点,但我想改变它,因为这种方法会不断地禁用键盘上的 NUMLOCK。
到目前为止,下面的函数可以工作,但该过程考虑了一个表单中的所有控件。它应该只考虑调用函数的同一部分或页面中的控件。为此,我需要知道活动控件是否位于页面和/或部分内,如果是,则此页面/部分的名称或索引。我找不到执行此操作的代码。
Public Function GotoNextTab()
Dim ctlNext, ctlCurrent As Control
Dim frmCurrent As Form
Dim lngNextTab As Long
Set frmCurrent = Screen.Activeform
Set ctlCurrent = Forms(frmCurrent.Name).ActiveControl
lngNextTab = Val(ctlCurrent.TabIndex) + 1
Do Until lngNextTab = frmCurrent.Controls.Count
For Each ctlNext In frmCurrent.Controls
Select Case ctlNext.ControlType
Case acCheckBox, _
acComboBox, _
acCommandButton, _
acListBox, _
acOptionButton, _
acSubform, _
acTabCtl, _
acTextBox, _
acToggleButton
If ctlNext.TabIndex = lngNextTab Then
If ctlNext.TabStop = True Then
'Make sure that the focus can be set here!
If ctlNext.Visible = True And ctlNext.Enabled = True Then
ctlNext.SetFocus
Exit Function
Else
'Focus could not be moved, so increase lngNextTab
lngNextTab = lngNextTab + 1
End If
Else
'This was the last tab, so exit
Exit Function
End If
End If
End Select
Next ctlNext
Loop
End Function
【问题讨论】:
-
关于表单的pages collection是什么意思?你的意思是Access 2003 feature?如果您可以分享这个有趣表格的屏幕截图。这个函数在哪里被调用?什么触发事件(OnOpen、OnClick、AfterUpdate)?
-
我在 v2010 中工作,但是是的,这正是我的意思。这些控件位于选项卡控件对象的不同页面上。 tabindex 值的范围仅限于标签页中的控件数量(否则我只会简单地连续编号)。这就是为什么我想知道控件位于哪个页面( Pages(Index) )上,