Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2005
    Posts
    11

    Unanswered: Creating a loop to write records

    I have a table, I have the sql statement I want, how do I write a loop to write these to a text file.

    For example,

    I could write
    Code:
    z.write (rstZ!Field1)
    z.write (";")
    z.write (rstZ!Field2)
    z.write (";")
    z.write (rstZ!Field3)
    z.write (";")
    And idea of what I am looking for is this

    Code:
    Dim size as Integer
    Dim i as Integer
    i = 1
    size = 1
    
    For i = 1 To client_a_size
    z.write (rstZ!FieldN)
    z.write (";")
    size = size +1
    Next i
    Thanks for any help, as I have tried everything...

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    I'm guessing you have tried everything except "docmd.TransferText" which exports data quite nicely.

    In database programming, you need to think more in terms of set-based operations rather than looping single-record actions.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Jan 2005
    Posts
    11
    I have not tried that. I did manage to get my loop to work, but seeing as how I am new to Databases, I will definitley read up on that this afternoon. Thanks for the tip!

  4. #4
    Join Date
    Aug 2003
    Location
    Cleveland USA
    Posts
    184
    First, create a recordset of the records you want to write to a file. There's more to it, but I'm not at my usual computer right now so I don't have a sample handy.

    Something like this:

    strSQL = "SELECT * from Z"

    rst = currentdb.openrecordset(strSQL)

    rst.MoveFirst

    Do while not rst.eof
    z.write (rstZ!Field1)
    z.write (";")
    z.write (rstZ!Field2)
    z.write (";")
    z.write (rstZ!Field3)
    z.write (";")
    .MoveNext
    Wend

  5. #5
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Please don't...
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  6. #6
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    I see what you mean....
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

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