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
3 2593
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.
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. . . -
Sub Import_data()
-
-
Dim dlgOpen As FileDialog
-
Dim vrtFileSelected As Variant
-
Dim db As Database
-
Dim sql As String
-
Dim del As String
-
-
Set db = CurrentDb
-
Set dlgOpen = Application.FileDialog( _
-
DialogType:=msoFileDialogOpen)
-
-
sql = "INSERT INTO PARTS SELECT * FROM PARTS1;"
-
del = "DROP TABLE PARTS1;"
-
-
' Prompt user for files to import
-
With dlgOpen
-
.AllowMultiSelect = True
-
.InitialFileName = "" 'You can put your folder location here or delete line to choose at run time
-
.ButtonName = "Import"
-
.Title = "Import Tables"
-
If .Show = 0 Then
-
MsgBox ("No files were selected. Import abandoned.")
-
Exit Sub
-
Else
-
For Each vrtFileSelected In .selecteditems
-
' The following line does the import. NOTE: This is taken from help files
-
DoCmd.TransferDatabase acImport, "Microsoft Access", _ vrtFileSelected, acTable, "PARTS"
-
db.Execute sql ' Copy Data from PARTS1 table
-
db.Execute del ' Delete PARTS1 table
-
Next
-
End If
-
End With
-
-
' Tidy up
-
Set dlgOpen = Nothing
-
Set db=Nothing
-
End Sub
-
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.
a small loop....using a query to move records from the "PARTS" table when its linked...into your "Final" table will work like so -
Function ImportDB()
-
Dim FSO As Object
-
Set FSO = CreateObject("Scripting.FileSystemObject")
-
Dim Fl As Object
-
strfolder = "C:\"
-
-
strFile = Dir(strfolder & "\fs*.mdb", vbNormal)
-
Do While strFile <> ""
-
If strFile <> "." And strFile <> ".." Then
-
' Link the Parts Table
-
DoCmd.transferdatabase acLink, "Microsoft Access", strFile, acTable, "Parts", "Parts", False
-
' Run your append query
-
CurrentDb.Execute "YourQueryName" '<--Your Append Query
-
' Remove the linked table so you can do it again
-
DoCmd.DeleteObject , acTable, "Parts"
-
End If
-
strFile = Dir()
-
Loop
-
Set FSO = Nothing
-
End Function
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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....
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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$) {
}
...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: 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...
| |