- Version
- Download 204
- File Size 362.16 KB
- File Count 1
- Create Date March 1, 2016
- Last Updated March 1, 2016
Search Function in Visual Basic 6 and MS Access
Search Function in Visual Basic 6 and MS Access
You will how to create a search function in visual basic 6.0 that is connected to ms access database.
The source code and step by step tutorial is included in the downloadable file.
Sample code of search function:
Sub SearchStudent()
Dim lstItem As ListItem
If rs.State = adStateOpen Then rs.Close
sql = " SELECT tblStudent.ID, tblStudent.studentName, tblStudent.studentAge, tblStudent.studentContact, tblStudent.studentAddress" & _
" From tblStudent" & _
" Where tblStudent.studentName='" & txtSearch.Text & "'" & _
" GROUP BY tblStudent.ID, tblStudent.studentName, tblStudent.studentAge, tblStudent.studentContact, tblStudent.studentAddress" & _
" ORDER BY tblStudent.ID;"
rs.Open sql, conn
ListView1.ListItems.Clear
Do While Not rs.EOF
Set lstItem = ListView1.ListItems.Add(, , rs(0).Value)
lstItem.SubItems(1) = rs(1).Value
lstItem.SubItems(2) = rs(2).Value
lstItem.SubItems(3) = rs(3).Value
lstItem.SubItems(4) = rs(4).Value
rs.MoveNext
Loop
MsgBox rs.RecordCount & " record(s) found for " & "" & txtSearch.Text
End Sub