防止向下箭头或向上箭头更新MS Access中的组合框

时间:2017-06-15 21:46:17

标签: access-vba

通常,当用户从组合框下拉列表中看到来自搜索字符串结果的结果时,自然响应是向下箭头指向他们精确定位的结果。

但是,如果我的用户单击向下箭头,它将更新组合框,从而不会按预期跳转到记录。如果用户点击“Tab”,“Enter”或鼠标点击,我想限制组合框仅检测更新。

我写的组合框搜索非常完美。

这是On Key Up事件中的代码

Private Sub cboGCPC_Search_KeyUp(KeyCode As Integer, Shift As Integer)
  Dim strSQL As String

        strSQL = "SELECT * " _
               & "FROM qryGCPC_Search " _
               & "WHERE [DocumentNumber] Like '*" & Me.cboGCPC_Search.text & "*' OR [Description] Like '*" & Me.cboGCPC_Search.text & "*' OR [Vendor] Like '*" & Me.cboGCPC_Search.text & "*' OR [Receiver] Like '*" & Me.cboGCPC_Search.text & "*';"


 Debug.Print strSQL

        Me.cboGCPC_Search.RowSource = strSQL
        Me.cboGCPC_Search.Dropdown

End Sub  

2 个答案:

答案 0 :(得分:0)

我认为你正在寻找类似的东西:

Private Sub cboGCPC_Search_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = 38 Then
        KeyCode = 0
        'Me.Combo0.Dropdown 'try this too, if necessary.
        'Exit Sub           'try this too, if necessary.
    End If
    If KeyCode = 40 Then
        KeyCode = 0
        'Me.Combo0.Dropdown 'try this too, if necessary.
        'Exit Sub           'try this too, if necessary.
    End If
End Sub

答案 1 :(得分:0)

这是我实施WAZZ答案的完整方式。

Private Sub cboGCPC_Search_KeyUp(KeyCode As Integer, Shift As Integer)
  Dim strSQL As String

        strSQL = "SELECT * " _
               & "FROM qryGCPC_Search " _
               & "WHERE [DocumentNumber] Like '*" & Me.cboGCPC_Search.text & "*' OR [Description] Like '*" & Me.cboGCPC_Search.text & "*' OR [Vendor] Like '*" & Me.cboGCPC_Search.text & "*' OR [Receiver] Like '*" & Me.cboGCPC_Search.text & "*';"


    Debug.Print strSQL


        Select Case KeyCode

        Case 38, 40

            KeyCode = 0

    Case 1, 9, 13
            Exit Sub

        Case Else
            Me.cboGCPC_Search.RowSource = strSQL
            Me.cboGCPC_Search.Dropdown

        End Select


End Sub