473,387 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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 2593
Rabbit
12,516 Expert Mod 8TB
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 Expert
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 Expert 512MB
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
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
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
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
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
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
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
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
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
Oralloy
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,...
0
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...

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.