Results 1 to 8 of 8

Thread: [RESOLVED] Search problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    26

    Resolved [RESOLVED] Search problem

    I have a database in access connected though ADO.

    I want to retrieve data from the table that contains many fields using a command button once inputed a unique field (id) and get rest of fields onto remaining textboxes.

    Thanks in advance

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Search problem

    VB Code:
    1. Dim sSQL As String
    2. sSQL = "SELECT field1, field2, field3 etc FROM tablename "
    3. sSQL = sSQL & "WHERE idfieldname = '" & txtId.Text & "' "
    4. Set rs = New ADODB.Recordset
    5. rs.Open sSQL, AdoConnectionObjName
    6. Text1.Text = rs.Fields.Item("field1").Value
    7. Text2.Text = rs.Fields.Item("field2").Value
    8. Text3.Text = rs.Fields.Item("field3").Value
    9. etc
    10. rs.Close
    11. Set rs = Nothing
    Where rs is the name of your recordset object and AdoConnectionObjName is the name of your connection object.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    26

    Re: Search problem

    Thank for the reply hack,

    What if the id it's not unique because have different dates?. If i have a button to scroll through the different dated id's and display rest of info on the textboxes.

    Thanks in advance

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Search problem

    Either select based on id and date to get a unique record, or select on based on id and get all records for that id.

    "WHERE idfieldname = '" & txtId.Text & "' And DateFieldName = #" & txtDate.Text & "#"
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    26

    Re: Search problem

    Thank for the reply,

    Now i´m having a problem, any value i input in the id txtbox returns the first row of the database.

    Al42,

    What i want it´s to retrive several records with the same id but different dates only.

    Thanks in advance.

  6. #6
    Addicted Member
    Join Date
    Jul 2006
    Posts
    147

    Re: Search problem

    cant you use what hack gave you to select the data then just use a for loop to display all records matching it?
    Im not sure on the code

    rs.Open sSQL, AdoConnectionObjName
    for i = 1 to rs.recordcount
    'Text1.Text = rs.Fields.Item("field1").Value
    'Text2.Text = rs.Fields.Item("field2").Value
    'Text3.Text = rs.Fields.Item("field3").Value
    'etc
    rs.movenext
    next
    rs.Close
    Last edited by Ishamael; Feb 27th, 2007 at 07:39 PM. Reason: bah

  7. #7
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Search problem

    if your returning several records then you might want to consider grid-like controls such as flexgrid or listview. Otherwise, using textboxes, you will have to provide control for navigating through the records. Often this is accomplished with data bound ado control but most would advise against using databound controls.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    26

    Re: Search problem

    Thanks all for your help.....Resolved

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