1,105,328 Community Members

How to search access database and display in Listview VB6?

Member Avatar
katie1988
Newbie Poster
1 post since Jul 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I'm creating a program where the user can search items in an access database and results are displayed in a listview.

When I click search all items are displayed but when I enter an item in the textbox then search nothing is displayed.

This is my code

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

I'm fairly sure the problem is with this line

If InStr(1, rs!Product, txtProduct.Text, vbTextCompare) Then

I need fresh eyes for this. Thanks :)

Member Avatar
Bile
Junior Poster in Training
96 posts since Dec 2010
Reputation Points: 10 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
1
 

-->>'M not so sure but may be try to look on this post ealier solve it may hel perhaps if not I'll try sometin else please let me know.
http://www.daniweb.com/software-development/visual-basic-4-5-6/threads/429015/help-with-search-data-in-database-with-textbox-and-listview

Question Answered as of 1 Year Ago by Bile
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: