无需鼠标即可反复使用MS-Access Combobox

时间:2014-09-21 20:03:32

标签: ms-access combobox access-vba

我使用组合框在未绑定的文本框中附加文本。我单击下拉箭头并开始键入(自动扩展,这是组合框的真正原因/用例)或单击选择。我可能想要再做2到3次。我不必再次点击下拉列表了。我只是想开始输入。这里的最后两行不适合我:

Private Sub cmboTag1_AfterUpdate()
    Me.txtTags.Value = Me.txtTags.Value & " " & Me.cmboTag1.Value
    Me.cmboTag1.SetFocus
    Me.cmboTag1.Dropdown
End Sub

有办法吗?

1 个答案:

答案 0 :(得分:1)

如果你没有强烈反感SendKeys(有些人这样做),那么这似乎对我有用:

Option Compare Database
Option Explicit

Dim cmboUpdated As Boolean

Private Sub cmboTag1_AfterUpdate()
    cmboUpdated = True
    Me.txtTags.Value = Me.txtTags.Value & " " & Me.cmboTag1.Value
End Sub

Private Sub cmboTag1_GotFocus()
    cmboUpdated = False
    SendKeys "%{DOWN}"
End Sub

Private Sub cmboTag1_LostFocus()
    If cmboUpdated Then
        SendKeys "+{TAB}"
    End If
End Sub