0

我正在尝试在活动中做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

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

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

谢谢

4

1 回答 1

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
于 2012-10-11T15:01:55.747 回答