我正在创建一个程序,用户可以在其中搜索访问数据库中的项目,结果显示在列表视图中。
当我单击搜索时,会显示所有项目,但是当我在文本框中输入项目时,则不会显示任何搜索。
这是我的代码
Private Sub cmdProdSearch_Click()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim list_item As ListItem
Dim itm As ListItem
db_file = db_file & "ProductsDatabase.mdb"
Set conn = New ADODB.Connection
conn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\VB and Database\ProductsDatabase.mdb;Persist Security Info=False" & _
"Data Source=" & db_file & ";" & _
"Persist Security Info=False"
conn.Open
Set rs = conn.Execute("Select * from Export")
ListView1.ListItems.Clear
If InStr(1, rs!Product, txtProduct.Text, vbTextCompare) Then
With ListView1
.View = lvwReport
.FullRowSelect = True
Do While Not rs.EOF
Set itm = .FindItem(txtProduct.Text, lvwText, , lvwPartial)
Set list_item = .ListItems.Add(, , rs!Product)
list_item.SubItems(1) = rs!barcode & ""
list_item.SubItems(2) = rs!quantity & ""
list_item.SubItems(3) = rs!Department
rs.MoveNext
Loop
End With
End If
End Sub
有什么想法有什么问题吗?我没有收到错误,只是没有显示。谢谢