Hi, I've been looking for a while for a means to achieve this but have so far drawn a blank so any help would be much appreciated.
I have 1 Access 2K3 database with circa 300 tables in, each of these tables have the same structure, but vary in thier length, and in some cases are just field headers. ( It was easier to import all data, as couldn't work out how to check prior to the import).
What I need to be able to do is to import all tables into 1 master table, however would like to avoid the need to append each table manually if possible.
The import requirement will pull the same columns from all source tables, and will also add the first 5 characters of the table name into the first field of the master table ( this first field does not exist within the source tables).
The code I have got so far is as follows:
I have created a table with all the table names in it as a point of reference, but I can't seem to get this code to work. Any help would be much appreciated.
Rob
I have 1 Access 2K3 database with circa 300 tables in, each of these tables have the same structure, but vary in thier length, and in some cases are just field headers. ( It was easier to import all data, as couldn't work out how to check prior to the import).
What I need to be able to do is to import all tables into 1 master table, however would like to avoid the need to append each table manually if possible.
The import requirement will pull the same columns from all source tables, and will also add the first 5 characters of the table name into the first field of the master table ( this first field does not exist within the source tables).
The code I have got so far is as follows:
Code:
Function data_upload_new()
Dim v_date, v_periodweek, x
x = 1
Do While x > 0
v_date = DLookup("[fld_name]", "tbl_table_names", "[fld_key] = x")
v_periodweek = Left(v_date, 5)
v_sql = "INSERT INTO tbl_master_data ( [v_periodweek], [customer id], [customer name], [mc pallets advised], [mc cages advised], [mc totes advised], [mc sets advised], [elc pallets advised], [mc cube in], [elc cube in], [arrival time], [departure time], [dwell time])" & _
"SELECT " & v_periodweek & " as v_periodweek, [" & v_date & "].[customer id], [" & v_date & "].[customer name], [" & v_date & "].[mc pallets advised], [" & v_date & "].[mc cages advised], [" & v_date & "].[mc totes advised], [" & v_date & "].[mc sets advised], [" & v_date & "].[elc pallets advised], [" & v_date & "].[mc cube in], [" & v_date & "].[elc cube in], [" & v_date & "].[arrival time], [" & v_date & "].[departure time], [" & v_date & "].[dwell time]" & _
"FROM [" & v_date & "];"
DoCmd.RunSQL v_sql
x = x + 1
Loop
End Function
I have created a table with all the table names in it as a point of reference, but I can't seem to get this code to work. Any help would be much appreciated.
Rob