在requery之后将光标保持在字段中的相同位置

时间:2012-10-11 14:50:27

标签: ms-access ms-access-2010

我正在autocomplete combobox事件中尝试keyUp这样做。

Private Sub Combo59_KeyUp(KeyCode As Integer, Shift As Integer)
    If Len(Combo59.Text) > 2 Then
        Combo59.RowSource = "SELECT City FROM Mills WHERE City LIKE '%" & Combo59.Text & "%' GROUP BY City ORDER BY City;"
        Me.Dirty = False
        Combo59.Requery
    End If
End Sub

问题是,在重新查询之后,它会选择字段中的所有文本,这样当用户按下下一个键时,它会删除所有内容。

是否有一种简单的方法,或者我必须找到光标位置并在重新查询后将其放回去?

谢谢

1 个答案:

答案 0 :(得分:2)

这可能需要一些调整,但它应该给你一般的想法:

Private Sub Combo59_KeyUp(KeyCode As Integer, Shift As Integer)
Dim SaveSelStart
    If Len(Combo59.Text) > 2 Then
        SaveSelStart = Combo59.SelStart
        Combo59.RowSource = "SELECT City FROM Mills WHERE City LIKE '%" & Combo59.Text & "%' GROUP BY City ORDER BY City;"
        Me.Dirty = False
        Combo59.Requery
        Combo59.SelLength = 0
        Combo59.SelStart = SaveSelStart
    End If
End Sub