CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2000
    Posts
    19

    Help on Access DB in VB

    I have a access DB called data1.mdb it has lots of fields in it like (First, Last, Address).

    I would like to make a form that when i type the last name of some one in TextBox1 it would then search the DB and fill in (first in TextBox2 and Address in TextBox3)

    I know must of it I Just don't know how to do a search.

    Thanks in Advance
    Donny S.


  2. #2
    Join Date
    Jul 1999
    Location
    USA
    Posts
    101

    Re: Help on Access DB in VB

    This is one of the ways:

    strFirst="select FirstName from data1.mdb where LastName =" & text1.text

    text2.text = strFirst



    What if there are 2 persons with the same last name?

    may be, you can use a count and if count>1, pop up a message box




  3. #3
    Join Date
    Jul 1999
    Location
    USA
    Posts
    101

    Re: Help on Access DB in VB

    sorry, it should be

    select FirstName from tableName where LastName = "

    You should open the connection obj and the recordset.


  4. #4
    Join Date
    Jan 2000
    Posts
    19

    Re: Help on Access DB in VB

    Ok I got it to work but it won't update the DB when I change the text in a text box or on exit


  5. #5
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: Help on Access DB in VB

    If the user will always have the exact name of the person they are looking for, then you can do as suggested above. But what if they dont know exactly how to spell the person's last name. Or they only enter the first few letters. Then you would have to search for wildcards.


    sql = "SELECT * FROM TableName WHERE LastName LIKE '%" & txtLastName.Text & "%'"




    The wildcard characters above are for SQL Server, you may have to try * instead of % for Access, I'm not sure about that.

    You could have an option button on the search form: One for exact search and one for wildcard search to distinguish when to use the LIKE clause and when not to.

    Good luck,
    John

    John Pirkey
    MCSD
    www.ShallowWaterSystems.com
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured