Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop Through Recordset and save results 3

Status
Not open for further replies.

Palmyra

Programmer
Jan 5, 2007
150
US
I need to open a recorset, select the first 22 names and name them so that I can output them to a text file. I created variables Name1, Name2, Name3, etc.

How can I set the value of the first 22 names to my variable names.

Select Number, Name from Table

Hope this is clear, any help appreciated.
 
Can I loop through the recordset this way but output to a comma, quote delimited file? "Name1", "Name2", "Name3", etc.
 
Sure - make another loop inside of the While Not RS.EOF loop, build a string and print it to the file.

What have you tried so far?
 
No, this is what I'm doing. Will you suggestion work ?

Open "C:\File.txt" For Output As #iFile
' Loop through the recordset
Print #iFile, ""
Print #iFile, "'" & fresults.Value("wmatter") & "'"
Print #iFile, "'" & fresults.Value("clname1") & "'"
Print #iFile, "'" & fresults.Value("mdesc1") & "'"
Print #iFile, "'" & fresults.Value("walltype") & "'"
While Not fresults.AtEnd
' Write each timekeeper to the file
Print #iFile, "'" & fresults.Value("wtimekeeper") & "'"
fresults.MoveNext
Wend
Print #iFile, "" & label
Close #iFile
 
Djangman, Try as I might, I can't make your suggestion work.
 
Something like:
Code:
Dim sOutputLine as string

   Open "C:\PalmyraTest.txt" For Output As #iFile

    ' Loop through the recordset
    While Not fresults.EOF
        ' Write each data item to a file
        sOutputLine = ""
        sOutputLine = sOutputLine & """" & fresults.Value("wmatter") & """" & ","
        sOutputLine = sOutputLine & """" & fresults.Value("clname1") & """" & ","

        'And so on

        Print #iFile, sOutputLine
        fresults.MoveNext
    Wend
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top