CREATE MANUAL HEADER LINE FOR CSV EXPORT

S

SEAN DI''''ANNO

Good afternoon, Using code snippets I have found, I have managed to create a
nice filter on a form. I am now trying to export the results of the query to
a csv file. The code below works fine except, I don't know how to write the
manual header to the csv file.

I currently have
'Create and write the header line
StrHeader = Chr(34) & "," & Chr(34)
StrHeader = Chr(34) & " Group No" & Chr(9) & "Group Name" & Chr(34)

At the moment, I just have Group No Group Name appearing in the first line
but all in the first column. Can some one please help?

This is all the code I am using

Dim dbsNorthwind As DAO.Database
Dim rstRecords As DAO.Recordset
Dim StrHeader As String

Set dbsNorthwind = CurrentDb

Set rstRecords = dbsNorthwind.OpenRecordset("SELECT
Qry_Corporate_Accounts.* FROM Qry_Corporate_Accounts " & BuildFilter)
Open "C:\SEAN.CSV" For Output As #1

'Create and write the header line
StrHeader = Chr(34) & "," & Chr(34)
StrHeader = Chr(34) & " Group No" & Chr(9) & "Group Name" & Chr(34)

Print #1, StrHeader

Do While Not rstRecords.EOF
Write #1, rstRecords![Group No], rstRecords![Corporate Name]
rstRecords.MoveNext
Loop

rstRecords.Close
dbsNorthwind.Close

Set rstRecords = Nothing
Set dbsNorthwind = Nothing
Close #1
 
D

Douglas J. Steele

You said it's a csv file. That means that columns need to separated by
commas.

StrHeader = Chr(34) & " Group No,Group Name" & Chr(34)
 
S

SEAN DI''''ANNO

Thanks Doug,

Can't believe it was that simple. lol


Douglas J. Steele said:
You said it's a csv file. That means that columns need to separated by
commas.

StrHeader = Chr(34) & " Group No,Group Name" & Chr(34)


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


SEAN DI''''ANNO said:
Good afternoon, Using code snippets I have found, I have managed to
create a
nice filter on a form. I am now trying to export the results of the query
to
a csv file. The code below works fine except, I don't know how to write
the
manual header to the csv file.

I currently have
'Create and write the header line
StrHeader = Chr(34) & "," & Chr(34)
StrHeader = Chr(34) & " Group No" & Chr(9) & "Group Name" & Chr(34)

At the moment, I just have Group No Group Name appearing in the first line
but all in the first column. Can some one please help?

This is all the code I am using

Dim dbsNorthwind As DAO.Database
Dim rstRecords As DAO.Recordset
Dim StrHeader As String

Set dbsNorthwind = CurrentDb

Set rstRecords = dbsNorthwind.OpenRecordset("SELECT
Qry_Corporate_Accounts.* FROM Qry_Corporate_Accounts " & BuildFilter)
Open "C:\SEAN.CSV" For Output As #1

'Create and write the header line
StrHeader = Chr(34) & "," & Chr(34)
StrHeader = Chr(34) & " Group No" & Chr(9) & "Group Name" & Chr(34)

Print #1, StrHeader

Do While Not rstRecords.EOF
Write #1, rstRecords![Group No], rstRecords![Corporate Name]
rstRecords.MoveNext
Loop

rstRecords.Close
dbsNorthwind.Close

Set rstRecords = Nothing
Set dbsNorthwind = Nothing
Close #1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top