473,480 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to copy contents of many tables to a single table without opening them

1 New Member
Hi, I have about 450 access files ( as001, as002,............, as450) in a folder. Each of the file contains a table named PARTS ( which contains 4 fields). Now I want to copy the contents of these tables from each of this access file into a single Table. can something be done with Macro.? Please help me to write the macro. I can copy paste manullay but it will take a long time. My knowledge level in ACCESS / VB coding is that of Beginers.
Plz help me
May 7 '07 #1
3 2595
Rabbit
12,516 Recognized Expert Moderator MVP
Hi, I have about 450 access files ( as001, as002,............, as450) in a folder. Each of the file contains a table named PARTS ( which contains 4 fields). Now I want to copy the contents of these tables from each of this access file into a single Table. can something be done with Macro.? Please help me to write the macro. I can copy paste manullay but it will take a long time. My knowledge level in ACCESS / VB coding is that of Beginers.
Plz help me
You'll probably want to start by looking at this tutorial for beginners then.

What you'll want to do is create a Loop that will import the table, append it to a main table, and delete the table.
May 7 '07 #2
kepston
97 Recognized Expert New Member
You can import the tables using VBA modules.
I do something similar with text files on a regular basis.
You can combine the tables in one hit, with a little extra code. . .

Expand|Select|Wrap|Line Numbers
  1. Sub Import_data()
  2.  
  3. Dim dlgOpen As FileDialog
  4. Dim vrtFileSelected As Variant
  5. Dim db As Database
  6. Dim sql As String
  7. Dim del As String
  8.  
  9. Set db = CurrentDb
  10. Set dlgOpen = Application.FileDialog( _
  11.     DialogType:=msoFileDialogOpen)
  12.  
  13. sql = "INSERT INTO PARTS SELECT * FROM PARTS1;"
  14. del = "DROP TABLE PARTS1;"
  15.  
  16. ' Prompt user for files to import
  17. With dlgOpen
  18.     .AllowMultiSelect = True
  19.     .InitialFileName = "" 'You can put your folder location here or delete line to choose at run time
  20.     .ButtonName = "Import"
  21.     .Title = "Import Tables"
  22.     If .Show = 0 Then
  23.         MsgBox ("No files were selected. Import abandoned.")
  24.         Exit Sub
  25.     Else
  26.         For Each vrtFileSelected In .selecteditems
  27. ' The following line does the import. NOTE: This is taken from help files
  28.             DoCmd.TransferDatabase acImport, "Microsoft Access", _  vrtFileSelected, acTable, "PARTS"
  29.             db.Execute sql ' Copy Data from PARTS1 table
  30.             db.Execute del ' Delete PARTS1 table
  31.         Next
  32.     End If
  33. End With
  34.  
  35. ' Tidy up
  36. Set dlgOpen = Nothing
  37. Set db=Nothing
  38. End Sub
  39.  
This code assumes you already have the table PARTS in your main database and that it has the same four fields as your 450 others.
I suggest that you prove this with a small selection of files to start with, that's the beauty of the Dialog box, it allows you to choose which files you want.
Please backup first.

I hope that helps. Let me know.
May 7 '07 #3
JConsulting
603 Recognized Expert Contributor
a small loop....using a query to move records from the "PARTS" table when its linked...into your "Final" table will work like so
Expand|Select|Wrap|Line Numbers
  1. Function ImportDB()
  2. Dim FSO As Object
  3.     Set FSO = CreateObject("Scripting.FileSystemObject")
  4.     Dim Fl As Object
  5.     strfolder = "C:\"
  6.  
  7.     strFile = Dir(strfolder & "\fs*.mdb", vbNormal)
  8.     Do While strFile <> ""
  9.         If strFile <> "." And strFile <> ".." Then
  10.             ' Link the Parts Table
  11.             DoCmd.transferdatabase acLink, "Microsoft Access", strFile, acTable, "Parts", "Parts", False
  12.             ' Run your append query
  13.             CurrentDb.Execute "YourQueryName"  '<--Your Append Query
  14.             ' Remove the linked table so you can do it again
  15.             DoCmd.DeleteObject , acTable, "Parts"
  16.         End If
  17.         strFile = Dir()
  18.     Loop
  19.     Set FSO = Nothing
  20. End Function
May 7 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
2021
by: heromull | last post by:
We have an asp.net app with about 200 data entry forms. Customers may enter data into any number of forms. Each form's data is persisted in a corresponding sql table. When data entry is...
5
2431
by: James Foreman | last post by:
I've got lots of different tables, each pertaining to a different marketing campaign. I have another table that stores the name & schema of each of these tables, together with other information...
3
8334
by: Tlm | last post by:
Hello All, I have a form (FrmA) with a subform (SubFrmB) embedded in it. SubFrmB also has a subform embedded in it (SubFrmC) The form's recordsource is based on a table (TblA). SubFrmB's...
7
11593
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
10
2286
by: Neo Geshel | last post by:
I am seeking to hand-roll my own blog in ASP.NET 2.0 and SQLExpress 2005. Why? Because I can. Because I will gain experience. The one thing that has me stumped at square one is inline images....
17
5071
by: Steve | last post by:
I'm trying to code cut, copy, and paste in vb 2005 so that when the user clicks on a toolbar button, the cut/copy/paste will work with whatever textbox the cursor is current located in (I have...
7
11535
by: Emin | last post by:
Dear experts, If I have a number of related groups of data (e.g., stock prices for different stocks) is it better to put them into many tables (e.g., one table per stock) or into one big table...
25
2853
by: Andy_Khosravi | last post by:
I just recently changed my database that I'm running from a monolithic DB to a split FE/BE. The front end resides on the client machine and the BE resides on a network drive. I'm experimenting with...
2
2847
TheServant
by: TheServant | last post by:
Hi everybody, I posted a similar question about 6~12 months ago with no definate answer, so I will give it another go, as the choice has popped up again in my programming life: If the number of...
0
7037
marktang
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,...
0
6904
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...
0
7076
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
6873
tracyyun
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...
0
5321
agi2029
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,...
1
4767
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4471
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2990
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
174
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.