DouglasMacArthur
New member
- Local time
- Today, 08:49
- Joined
- May 19, 2016
- Messages
- 5
Hi all,
I'm new to this forum and relatively new to VBA, so from what I can tell, this problem should be pretty simple to resolve.
Basically, I need to read in a bunch of excel files to a single database table and add a column that contains the name of the file each entry originated from. My approach is to create a new table for every file, pass through the data, then create a column called "Source" and populate it with the name of the file. Then, I would pool all of those tables together into one.
So far, I have most of it done; I can pass through the data to individual tables and a column called "Source" is added to each one. Where I am stuck is filling in that column in each table with the file name.
My first approach was to just set the DefaultValue property as the file name, which executes and the Default Value is set, but this only fills one cell at the end with the file name. Now I've been trying to use SQL, but with no results.
Here's the line where I make my SQL attempt:
Perhaps I'm going about this ↑ entirely wrong but I can't really tell. As I said, I'm fairly new to this. Any help is appreciated!
I'm new to this forum and relatively new to VBA, so from what I can tell, this problem should be pretty simple to resolve.
Basically, I need to read in a bunch of excel files to a single database table and add a column that contains the name of the file each entry originated from. My approach is to create a new table for every file, pass through the data, then create a column called "Source" and populate it with the name of the file. Then, I would pool all of those tables together into one.
So far, I have most of it done; I can pass through the data to individual tables and a column called "Source" is added to each one. Where I am stuck is filling in that column in each table with the file name.
My first approach was to just set the DefaultValue property as the file name, which executes and the Default Value is set, but this only fills one cell at the end with the file name. Now I've been trying to use SQL, but with no results.
Here's the line where I make my SQL attempt:
Code:
CurrentDb.Execute "UPDATE "" & TableName & "" SET [Source] = "" & sName & """
'Where TableName is a string variable referencing a specific table and sName is the file name
Perhaps I'm going about this ↑ entirely wrong but I can't really tell. As I said, I'm fairly new to this. Any help is appreciated!