Results 1 to 6 of 6

Thread: [RESOLVED] Creating a text file from a recordset

  1. #1

    Thread Starter
    Junior Member beatlesgal25's Avatar
    Join Date
    Feb 2006
    Location
    Swansea, Wales
    Posts
    22

    Resolved [RESOLVED] Creating a text file from a recordset

    Hi there

    I have a table in Access 2002 and I need to create a text file from a recordset in VB6. I have set up the connection (and so on) but when I try to read the values from the recordset into a label, only the last value is displayed - as if the other values are being overwritten.

    I know the values are there as I have tried using a msgbox and this displays them fine.

    Below is the snippet of code I am using:

    VB Code:
    1. Do While Not rs.EOF
    2.     label1.Caption = rs.Fields("order_item").Value & vbCrLf
    3.     rs.MoveNext
    4. Loop

    Can anyone help me please? This might be a really simple question, but I'm not the best of programmers.

    Many thanks!
    Emma.

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

    Re: Creating a text file from a recordset

    Welcome to the forums.

    Love your username!

    If you want to write your recordset to a text file why are you trying to display in in a label? Why not just write it to the file?

    Also, if need to display the recordset on a screen, then rather than a label, I would use a multiline textbox.

  3. #3

    Thread Starter
    Junior Member beatlesgal25's Avatar
    Join Date
    Feb 2006
    Location
    Swansea, Wales
    Posts
    22

    Unhappy Re: Creating a text file from a recordset

    Thank you for your warm welcome!

    I did try to write it straight to the text file originally, but I was having the same problem (the previous values were being overwritten).

    I tried your idea of a multiline text box, but again it only displays the last value.

    I'm getting a bit stuck here

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

    Re: Creating a text file from a recordset

    Try this
    VB Code:
    1. label1.Caption = label1.caption & rs.Fields("order_item").Value & vbCrLf

  5. #5

    Thread Starter
    Junior Member beatlesgal25's Avatar
    Join Date
    Feb 2006
    Location
    Swansea, Wales
    Posts
    22

    Resolved Re: Creating a text file from a recordset

    Of course! I see now why it was overwriting what was being read originally

    My text file is now working too! Many thanks!

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

    Re: Creating a text file from a recordset

    Quote Originally Posted by beatlesgal25
    Of course! I see now why it was overwriting what was being read originally

    My text file is now working too! Many thanks!
    No problem.

    If this is resolved, please pull down the Thread Tools menu and click the Mark Thread Resolved button. That will let everyone know that you have your answer.

    Thank you.

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