Searching In VB

Posted on 2006-04-03
Last Modified: 2010-05-01
I have three three text boxes namely first name, last name and DOB

 and one datagrid in which i am displaying the  table "students"

I want when the user enters any value in any of the three boxes ( either the full first name, or last name or either the first three letters of  first  or last name , or only DOB),  and click on "Search" button:-

The datagrid will only search  on the basis  of above criteria  and will display the values  from the database... in the datagrid...........................................

Please help me in VB only  as i need it urgently
Question by:rajender123
    LVL 48

    Accepted Solution

    in your Search button, try add like:

    SQL = "Select * from yourTable "
    tmp = " WHERE "
    If FirstName.Text <> "" then tmp = tmp & " FirstName Like '%" & Replace$(FirstName.Text,"'","''") & "%' And "
    If LastName.Text <> "" then tmp = tmp & " LastName Like '%" & Replace$(LastName.Text,"'","''") & "%' And "
    If DOB.Text <> "" then tmp = tmp & " DOB = #" & DOB & "# And "     'Change # to ' if necessary, depends on your database using

    If tmp = " WHERE " then
        tmp = ""
       tmp = left$(tmp, len(tmp) - 4)
    End if
    SQL = SQL & tmp

    If rs.state = adStateOpen Then rs.Close
    rs.Open SQL, conn, adOpenKeyset, adLockOptimistic

    Set datagrid1.DataSource = rs

    Author Comment

    Thanks.. for this...  i want that when the serch results come in datagrid...(since i have  multiple values  of  the same student  with different dates) so the datagrid  will display all the values......................... of  ame student with different visit dates..........

    Now  i   want if i  select one row...... all the records will be displayed in the text boxes:- namely

    first name
    last name
    visit date

    Also, the search results  should also be present  at the same time....................

    Can u please help  me out in VB.............................................
    LVL 48

    Expert Comment

    by:Ryan Chong
    >>Now  i   want if i  select one row...... all the records will be displayed in the text boxes:- namely
    I think this is the new question from this thread, you can try:

    1. Open a New Question with this requirement or
    2. Increase this question's points

    so that we can help here.


    Author Comment

    I have  increased the points  also

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now