Help with Excel VBA project using a folder of text files as relational database

largeselection

Active Member
Joined
Aug 4, 2008
Messages
358
This is a bit complicated...<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
Basically I have recaps (excel based reports) which run every wednesday. They are typically approx 1000 rows x 70 columns. One of the columns is usually "ID#" which is common across most of the reports. What I have started doing is saving them as CSV files into a main folder. I have used Excel to "connect to an external data source" using the text driver and connecting to that main folder. That way I can run queries and define relationships pulling information from all the different text reports in the folder without having to do a lot of lookups. <o:p></o:p>
<o:p> </o:p>
The issue is that there are a lot of reports to sift through and select fields from when trying to do analysis. So what I am attempting to do is create a front end which is simpler and more graphical. <o:p></o:p>
<o:p> </o:p>
So far I have created the beginnings of a userform in excel and ultimately the goal would be that I could select things on the userform, have it translate the selections into SQL which I can then pass to MS Query and then have the resultant data set returned back into Excel. <o:p></o:p>
<o:p> </o:p>
The reports are named with the same convention:<o:p></o:p>
REPORT#_Area#_Month#Week#_Year#<o:p></o:p>
<o:p> </o:p>
The fields in the reports are also similarly named:<o:p></o:p>
Time Period (weekly, monthly, quarterly, etc)_ Field_Unit of measurement($, %, etc)_Qualifier(TY, NY)<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
This is my thought process and what I am looking for is suggestions since as I am doing this I keep thinking that I’m sure there is a more elegant way to get this done…<o:p></o:p>
<o:p> </o:p>
In the userform I have some comboboxes which have the report fields<o:p></o:p>
1- Month<o:p></o:p>
2- Week<o:p></o:p>
3- Year<o:p></o:p>
4- Report#<o:p></o:p>
5- Area#<o:p></o:p>
<o:p> </o:p>
So far I have it so that I can select which month week etc info and then it will populate an excel sheet with the selected info when I click a button. This process allows me to add the first parts of the SQL statements.<o:p></o:p>
<o:p> </o:p>
My SQL statements are usually:<o:p></o:p>
SELECT RPT155_A10_MarWk1_2010.’WEEKLY_BIKETRAVEL_%_TY’<o:p></o:p>
FROM ‘<MAIN FOLDER LOCATION>’\RPT155_A10_MarWk1_2010.csv RPT155_A10_MarWk1_2010<o:p></o:p>
WHERE RPT155_A10_Marwk1_2010.’ID#’ = RPT155_A10_Aprwk5_2010.’ID#’<o:p></o:p>
<o:p> </o:p>
With my userform passing the selections to the excel worksheet I can build the “RPT155_A10_MarWk1_2010” part. And then string many of them together which I will ultimately pass through to MS Query. The problem is that when I get to trying to add the second half of the statement (the fields) there are tooo many! I was originally planning on using a section of checkboxes in the userform and then pass through the checked boxes values to the excel sheet, but that takes too much memory in excel. <o:p></o:p>
<o:p> </o:p>
So does this sound as crazy as I think it is? Is there a better way of trying to simplify pulling information from a quasi relational database constructed of text files in a folder? Any suggestions on how I can have the available fields/reports populate based on the reports in the main folder? <o:p></o:p>
<o:p> </o:p>
Sorry for the long, confusing post, but this is usually the place I turn when I have something too complicated for many others haha.<o:p></o:p>
<o:p> </o:p>
Thanks for any suggestions.<o:p></o:p>
 
As an alternative, Is there any way in VBA to pull the Column headers (Field names) from each report and list them next to the report names in the folder?

I have some code which will pull the names of all the files in the main folder into an excel sheet, so what I would want to do is list the column headers available for each file next to its name in the sheet. Then I might be able to use that info to generate SQL statements a bit more simply rather than using a userform.
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top