Re: [VB6 ] combo 如何在輸入期間同時飾選資料?
※ 引述《Hotan (昊天)》之銘言:
: 如題,每輸入一個字就更新一次combo裡符合的內容
: Private Sub Combo2_Change()
: CN.Open ConnString
: sql = "SELECT * FROM customer "
: sql = sql & "WHERE customer_No is not null"
: If (Combo2.Text <> "") Then sql = sql & " and customer_Name = '" & Combo2.
: Text & "%' "
: combo2.clear
: ^^^^^^^^^^^^
: '這個清除找不到正確的位置..@@ 輸入完也清除了,查也沒查,不能放在change裡?
: '請問我遺落了什麼嗎?? 希望能得到前輩們的指教,怎樣可以做到?? 謝謝 ^^
: RS.Open sql, ConnString, , , adCmdText
: While RS.EOF = False
: Combo2.AddItem RS("customer_Name")
: RS.MoveNext
: Wend
: CN.Close
: RS.Close
: End Sub
感覺好像是錯在SQL的語法~~~@@a
剛剛我測試了一下是可以的~~~
以下是我的部份程式碼,查詢對象是MS-SQL的北風資料庫~~~
如有其他錯誤,萬請指教~~~:)
Private Sub Combo1_Change()
Dim Length As Integer
Set objRst = New ADODB.Recordset
strRst = "Select * From Customers Where CustomerID like '" & Combo1.Text &
"%'"
objRst.CursorLocation = adUseClient
objRst.Open strRst, objConn, adOpenStatic, adLockPessimistic
If objRst.RecordCount > 0 Then
Length = Len(Combo1)
Combo1.Clear
While Not objRst.EOF
Combo1.AddItem objRst.Fields("CustomerID")
objRst.MoveNext
Wend
End If
Combo1.ListIndex = 0
Combo1.SelStart = Length
Combo1.SelLength = Len(Combo1)
objRst.Close
Set objRst = Nothing
End Sub
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.160.63.39
討論串 (同標題文章)