Results 1 to 3 of 3

Thread: recordset: Why does it only display the last record?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Posts
    18

    Question recordset: Why does it only display the last record?

    on button click event:

    dim atext as string

    atext=text1.text

    rs.Open "SELECT Name,Address,Category FROM tbl_sample WHERE Name='" & atext & "' ORDER BY Name", cn

    rs.MoveFirst
    Do Until rs.EOF = True
    Text2.Text = rs!Name & vbCrLf & rs!Address & vbCrLf & rs!Category & vbCrLf & vbCrLf
    rs.MoveNext
    Loop
    rs.Close
    Set rs = Nothing


    there are a total of 5 records/rows.
    but the text2 box only displays the last one.
    i suspect the problem is in the loop.
    pls help. thanks.
    life's full of probs!

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Your current statement is just overwriting the textbox with the data from each record. You need to concatenate each row to the textbox same as you do with each field.

    Text2.Text = Text2.Text & rs!Name & vbCrLf & ...

    You might want to clear the Textbox before your loop begins.

  3. #3
    Lively Member
    Join Date
    Nov 2002
    Location
    Michigan
    Posts
    107
    And make sure you have multiline set to true in your textbox.

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