-
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!!!
:)
-
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. :)