vba Access Excel SQL - Create Excel Header File

I am building a tool for a user who gets csv file report exports from a database, but they are missing the header row.  By header rows, I mean the first row of the excel/csv file that contains the field name/column name.  I'll call it a field name.

The same 50-100 reports export each day/week/month.  I've been asked to set up an MSAccess tool that will automate the function of inserting the field names.  I will need to store a header record (file? table?) of each report's field names. Each report has a unique number assigned that will be the link between the report and the header record. I'll build an entry form for creating a new header record, and for setting up the relationship link to it's report.  That's where it gets foggy. I can't save the header as a text field because it will often exceed the 255 char limit of this data type.  The my first ideas for how to proceed are:
 1) Have the user enter a row (in a unique table) for each column of the report.  Then save the header out as a unique table, probably using the report number for the table name.
2) Just like above, have the user enter a row for each column of the report, but then save it out to an excel file, with each row becoming a column in the excel file. Would make it easy for the next step of inserting it into the report.
3) Create and export a text file and save each column name with a delimiter comma.  Then call it up and read it back in with a loop to insert as field names.

I'd like to bounce this off someone to see if there is a better idea out there that I haven't considered.  Any thoughts?
Who is Participating?
Michael FowlerSolutions ConsultantCommented:
I would definately use my first solution.
The front page(or userform set to open on workbook open) would hold the check list, a hidden sheet would hold the headers.
Then for each selected report

Create a new sheet
Insert the appropiate header
Get CSV location
Open CSV
Insert Data into new sheet
Format sheet
Save sheet as new workbook in required location with appropiate name

LambelAuthor Commented:
Where is everyone today? Company Xmas party??
Michael FowlerSolutions ConsultantCommented:
Some ideas

A generic excel document with the headers stored as a table on a work sheet. You could then write a macro that imports the required csv, adds the appropiate header and saves the new file. The beauty of this would be that multiple files could be processed similtanously as well as renaming the reports, adding formating, formulas and any other tweaks you can think of.

Instead of having a unique table for each report, why not use one table and have a field for report name/number and then fields for header1, header2 etc. From there it should not be hard to extract a csv string of the header for each report.

Have you looked into the reason why the headers are missing? It may beeasy to just have the extraction add these headers.

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

LambelAuthor Commented:
Michael: Thanks for your reply.
I didn't mention that the user wants to be offered a list of reports with checkboxes that can be selected for all the reports (multiple at the same time) that would be reformated.  There will be a table in the Access database that will hold the source csv file of the report and the header file. To put them together, a routine will open a new excel file, insert the header (which is row 1), and then (using a loop) insert all the rows of data from the csv file and save it out to a specified folder.
Also - the option of fixing the export was shot down.
LambelAuthor Commented:
I mis-spoke:  There will be a table in the MSAccess database that will hold the LOCATION of the source csv file (not the csv file).
LambelAuthor Commented:
thanks for your suggestions. I preferred to build this in access, so I am using a table to hold the header records.  I will build the table as illustrated:
ReportID      HeaderField     SortOrder
001             xxx                    20
001             yyy                    10
001             aaa                    15
002             111                    10
003             111                    20
I should have thought of this, but I didn't.  Either way, this will work well with my design.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.