Results 1 to 2 of 2

Thread: writing to text files help me please!!!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    81
    at the moment im extracting data from my SQL database to an Excel file using my Vb command button "Extract To File"
    how do i make headings first then display the values under the headings ie one heading is profit and i want my extractions from sql to fall under the heading Profit i can display my data from slq database in excell but dont know how to write headings first any ideas???
    all help needed ,thankyou!!!



  2. #2
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    I'm not really sure what you are doing.

    The topic of your post said "Writing to Text Files" and yet your message says "Writing to Excel".

    If I am good at decrypting things (which I hope I am) I think what you REALLY are doing is writing to a text file called an "CSV" file and then IMPORTING that file into Excel so that it automatically spaces everything out.

    If that IS the case then all you need to do for headings is simply write the FIRST line to your CSV file containing the headings you want.

    ie :
    Code:
    Open "c:\outfile.csv" for OUTPUT as #1
    
    Print #1, "Profit,Loss,Another Heading,And Another"
    Do While not rstSQL.EOF
        Print #1, rstSQL("field1") & "," & rstSQL("field2") ...
        rstSQL.MoveNext
    Loop
    
    Close(1)
    So you do exactly what you are normally doing but you need that one extra print #1 line in before you start outputting your data to the file.

    Hope I read your question well.

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