954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

search command in vb

please i need a code that can help me search records from a table in vb.

az_master
Newbie Poster
15 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 
please i need a code that can help me search records from a table in vb.

check out this code. this code used the followings :-

DATABASE : student.mdb
TABLE : details
FIELDS : roll, name
DB LOCATION : same as the project folder
OUTPUT CONTROLS : txtrollno (for holding roll no) and txtname (for holding name)

replace those in the above with your own stuffs

Dim db As Database
Dim rs As Recordset
Dim str As String, confirm As Integer

Set db = OpenDatabase(App.Path & "\student.mdb")
Set rs = db.OpenRecordset("details", dbOpenTable)
If rs.RecordCount > 0 Then rs.MoveFirst

begin:
str = InputBox("Enter student roll no :", "Search Student")
If Trim(str) = "" Then
    confirm = MsgBox("No roll no. has been supplied." & vbCrLf & "Do you wish to abort searching?", _
    vbQuestion + vbYesNo, "Search")
    If confirm = vbNo Then
        GoTo begin
    Else
        Set rs = Nothing
        Exit Sub
    End If
Else
    Set rs = db.OpenRecordset("select * from details where roll='" & Trim(str) & "'", dbOpenDynaset)
    If rs.RecordCount > 0 Then
        txtrollno.Text = rs!roll
        txtname.Text = rs!Name
    Else
        confirm = MsgBox("No student with RollNo. " & str & " has been found." & vbCrLf & "Would you like to re-search?", _
            vbQuestion + vbYesNo, "Result")
        If confirm = vbNo Then
            Set rs = Nothing
            Exit Sub
        Else
            GoTo begin
        End If
    End If
End If


let me know if this helps you.

regards
Shouvik

choudhuryshouvi
Posting Pro
553 posts since May 2007
Reputation Points: 30
Solved Threads: 49
 

Nice one...

jireh
Posting Whiz
316 posts since Jul 2007
Reputation Points: 11
Solved Threads: 49
 

For searching it is always better to use LIKE than "="

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

i want to search command from excel to vb, unfortunately still not found, kindly help me. i'm using excel workbook as my database. i don't know how to create


workbook database= MasterTrackDB.xls
sheet1=ProRegister

daliyea
Newbie Poster
1 post since Mar 2012
Reputation Points: 10
Solved Threads: 0
 

Please start your own thread if you have a new question

ChrisPadgham
Posting Pro in Training
413 posts since Sep 2009
Reputation Points: 102
Solved Threads: 78
 

Post: Markdown Syntax: Formatting Help
You