I have vb form that accepts input from user,search in database(database acess) and displays matching records if any in the listview .The problem is that the search query will display only one matching record even if there are many matching records
.anyone please help

Recommended Answers

All 13 Replies

Make use of a loop...

Dim xRecords As Integer

rs.MoveFirst 'change rs to whatever you have named your recordset selector

For xRecords = 1 To rs.RecordCount
    ''Do with this record returned what you need to...

    rs.MoveNext
Next xRecords

use loop after search query

While rec.EOF = False
'write here what you wants (display records)
rec.MoveNext
wend

hope this helps you

AndreRet & rishif2 thanks for the help ...but inside the loop the list view is not working.

what code did you use to perform the desired task . . . . ?

I am not able to post the code here.I made use of list view for displaying the records

Dim li1 As ListItem
Dim x As Integer
LV1.ListItems.Clear
Do Until rs.EOF
Set li1 = LV1.ListItems.Add()
For x = 1 To 7
List.SubItems(x) = rs(x)
Next x
rs.MoveNext
Loop

The list view doent display the matching records

Your problem is the rs(x) part. You can loop through records but not through fields...

Well you can, but that is a totally different issue which is quite complex. :)

What you need to do is to change your code to -

Dim li1 As ListItem
''Dim x As Integer

LV1.ListItems.Clear

Do Until rs.EOF
Set li1 = LV1.ListItems.Add()
''For x = 1 To 7 Don't need this...
    List.SubItems(1) = rs!FieldName1
    List.SubItems(2) = rs!FieldName2
    List.SubItems(3) = rs!FieldName3
    ''etc...
''Next x
    rs.MoveNext
Loop

Whats happening is that you will start with record one and add it to your listview coloumn by coloumn.
rs will then move to the next and so on adding each rows data to your listview.

List.SubItems(1) = rs!FieldName1 is throwing error

Did you change FieldName1 to your own field name i.e. Id or name etc... ?

Yes .thanks for the help AndreRet

What error message are you getting?

thank you so so much for that code...it helped me a lot..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.