PC Review


Reply
Thread Tools Rate Thread

Copy data from one databse tabel to other database table

 
 
K
Guest
Posts: n/a
 
      23rd Jun 2011
Hi all, I have about 70 databases in folder "C:\Records\Databases" and
I have one database called "Main" in folder "C\Documents\Data". I
need macro in database "Main" which should loop through all 70
databases in folder "C:\Records\Databases" and copy data from table
"T_Output" of each database and paste into table "T_Input" of database
"Main" in folder "C:\Documents\Data". Please can any friend can help
me on this.
 
Reply With Quote
 
 
 
 
John Spencer
Guest
Posts: n/a
 
      23rd Jun 2011
I don't know of a way to do this with a macro. You could use a VBA routine to
do so. The following is a completely UNTESTED routine that you could add to
the Main database and try.

If you do try this I suggest you make a backup FIRST. It may not give you
what you want, it may partially work, or it may introduce other problems into
your data.

By the way I assumed (you did not say) that your databases are .mdb format.
If they are .accdb format then you will need to change .mdb in the following
code to .accdb

Public Sub sCopyData()
Dim strSQL As String
Dim strExecute As String
Dim dbAny As DAO.Database
Dim strPath As String
Dim strDBName As String

strPath = "C:\Records\Databases\"
Set dbAny = CurrentDb()
strSQL = "INSERT INTO T_Input (NameOfField1, Field2, NameofField3" & _
" SELECT NameOfField1, Field2, NameofField3 FROM T_Output" & _
" IN '" & strPath

strDBName = Dir(strPath)

While Len(strDBName) > 0
If strDBName Like "*.mdb" Then 'check to see if the file is an db
strExecute = strSQL & strDbName & "'"
dbAny.Execute strSQL, dbFailOnError
End If
strDBName = Dir(strPath)
Wend

End Sub

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

On 6/23/2011 6:30 AM, K wrote:
> Hi all, I have about 70 databases in folder "C:\Records\Databases" and
> I have one database called "Main" in folder "C\Documents\Data". I
> need macro in database "Main" which should loop through all 70
> databases in folder "C:\Records\Databases" and copy data from table
> "T_Output" of each database and paste into table "T_Input" of database
> "Main" in folder "C:\Documents\Data". Please can any friend can help
> me on this.
>


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete the data from tabel in the database =?Utf-8?B?SHVzYW0=?= Microsoft ADO .NET 1 18th Jun 2007 05:54 AM
copying data from tabel to table Simon Microsoft Access 3 30th Nov 2006 06:02 PM
Copy a database automatically when the databse closes =?Utf-8?B?SmVmZkgxMw==?= Microsoft Access Macros 3 2nd May 2005 04:46 PM
Copy data from one table to another in the same database file in . =?Utf-8?B?Q29sbGV0dGUgRm94?= Microsoft Access External Data 2 13th Oct 2004 01:31 PM
database name from linked tabel Leeuw1960 Microsoft Access Form Coding 1 16th Apr 2004 07:30 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:06 AM.