I need to append 300 tables (same columns, possible diff formats) onto 1 in Access.
All the tables start with the same name.
I used to have a piece of code that i ran that would simply pull all tables into 1 but have since lost it.
I have to be honest and say i have no VB skills what so ever and i think this is the only way this could be done quickly.
Here is some example code, you will need to modify as appropriate. - Public Sub CreateAndAppend()
-
'Create table
-
Dim tblDef As DAO.TableDef
-
Set tblDef = CurrentDb.CreateTableDef("tempTable", , , CurrentProject.Connection)
-
-
With tblDef
-
.Fields.Append .CreateField("KEY_Hazard", dbLong)
-
.Fields.Append .CreateField("mem_Title", dbMemo)
-
.Fields.Append .CreateField("ID_CreatedBy", dbLong)
-
.Fields.Append .CreateField("dt_Created", dbDate)
-
End With
-
-
CurrentDb.TableDefs.Append tblDef
-
-
'Cleanup
-
Set tblDef = Nothing
-
Dim oTbl As Object
-
For Each oTbl In CurrentData.AllTables
-
If Left(oTbl.Name, 5) = "excel" Then
-
DoCmd.SetWarnings (False)
-
DoCmd.RunSQL "INSERT INTO tempTable ( KEY_Hazard, mem_Title, ID_CreatedBy, dt_Created )" & _
-
" SELECT [Hazard ID], Title, User, Date " & _
-
" FROM [" & oTbl.Name & "]"
-
DoCmd.SetWarnings (True)
-
End If
-
Next
-
-
'cleanup
-
Set oTbl = Nothing
-
End Sub
You write that all your tables start with the same letters, in this example I append all tables called "excel....." to the first table I create.
3 2740
Hi what do you mean by diff formats?
How many coloumns are there and what are the formats?
1. longwinded way would be to create a union query of 300 tables. But this would be view only.. data can only be added to original tables.
2. a.we can store all the table Names into a temporary Table
b. Read the contents of each table
c. Append to new table usng SQL
"Hi what do you mean by diff formats?" What I mean by this is that the excel sheets have different formats in the columns. But they all should be text columns.
I would prefer to use method 2 as i have to do this for several lots of data.
What do i need to put in the module?
Here is some example code, you will need to modify as appropriate. - Public Sub CreateAndAppend()
-
'Create table
-
Dim tblDef As DAO.TableDef
-
Set tblDef = CurrentDb.CreateTableDef("tempTable", , , CurrentProject.Connection)
-
-
With tblDef
-
.Fields.Append .CreateField("KEY_Hazard", dbLong)
-
.Fields.Append .CreateField("mem_Title", dbMemo)
-
.Fields.Append .CreateField("ID_CreatedBy", dbLong)
-
.Fields.Append .CreateField("dt_Created", dbDate)
-
End With
-
-
CurrentDb.TableDefs.Append tblDef
-
-
'Cleanup
-
Set tblDef = Nothing
-
Dim oTbl As Object
-
For Each oTbl In CurrentData.AllTables
-
If Left(oTbl.Name, 5) = "excel" Then
-
DoCmd.SetWarnings (False)
-
DoCmd.RunSQL "INSERT INTO tempTable ( KEY_Hazard, mem_Title, ID_CreatedBy, dt_Created )" & _
-
" SELECT [Hazard ID], Title, User, Date " & _
-
" FROM [" & oTbl.Name & "]"
-
DoCmd.SetWarnings (True)
-
End If
-
Next
-
-
'cleanup
-
Set oTbl = Nothing
-
End Sub
You write that all your tables start with the same letters, in this example I append all tables called "excel....." to the first table I create.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: freeagent |
last post by:
Help!!
I am a complete Access newbie and I have to concatenate about 30
tables into one large table. All these tables have the same column
headings as each other.
For example, I have TABLE...
|
by: Access Newbie |
last post by:
I'm using Access 2000 and I'm trying to create a pass-through query to
append all the data from a local table to a remote table.
I'm using the SQL query editor in MS Access to create the query (I...
|
by: Eli Sidwell |
last post by:
I have an Access DB that contains 5 tables for the last 5 years. All 5
tables have the same structure. I wanted to keep each year separate
for organizational purposes.
But, I want to query all 5...
|
by: Art |
last post by:
Hi everyone
I was hoping someone might be able to help me with this. I'm just starting to try to work with MS Access tables through VB.net. In Access I can take an existing table and add a new...
|
by: Shwetabh |
last post by:
Hi,
I wanted to know if it is possible to do to append two tables into a
third table.
For example, consider these two tables
Table 1...
|
by: buddyr |
last post by:
I have two tables: table1 and table2
The fields are the same in both tables.
There are duplicate records of table1 and new records not in table1 in table2.
I have to add the new records to table1...
|
by: Troels Arvin |
last post by:
Hello,
Every so often, I'm asked to help people recover data from tables that
were either dropped or where to much data was DELETEed.
The complications related to restoring data are a problem....
|
by: meacho |
last post by:
i'm trying to append 5 tables the problem is that although most of the columns are the same the are on or two or so unique columns in each table. I would like to append the tables creating one table...
|
by: babamc4 |
last post by:
I have a main form (mainformlung) with 5 subforms (followupacute, followuplate, biochemresults, haemresults and pftresults). I have copied Allen Browne's Audit Trail code (thanks to Allen Browne)...
|
by: manojspromantr |
last post by:
I'm trying to append some data from one table to another table both the table structure are same. I have an attachments field in both tables but it seems that i cannot append the attachments from one...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |