Solved

Copying access tables to a central access database

Posted on 2004-04-19
5
218 Views
Last Modified: 2010-05-02
i need to know how to copy, through code, several tables from different access databases scattered over the network to a central access database.  i need the tables to be overwritten during the copy operation.  i was hoping this could be done through sql.  any help is greatly appreciated.
dennis
0
Comment
Question by:superbeast23
  • 2
5 Comments
 
LVL 11

Expert Comment

by:SweatCoder
ID: 10863716
sql would be best, but i have an adox solution if you need it:

http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=697
0
 
LVL 2

Expert Comment

by:MrPan
ID: 10866936
Not exact code but to give you the idea

CopyTable ("COMPANY","c:\old.mdb","c:\new.mdb")

----------------------------

Function CopyTable(TableName as string,DataSource as string, DataPathnew as string)

dim conn as adodb.connection
Set Conn = New ADODB.Connection

Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
           "Data Source=" & DataSource & ";" & _
           "User Id=admin;" & _
           "Password=;"

conn.execute "Delete * From " & tableName

        Ssql = "INSERT INTO " & TableName & _
        " IN '" & DataPathNew & "' SELECT " & TableName & ".* From " & TableName
        Conn.Execute (Ssql)
        conn.close
end Function
0
 
LVL 2

Accepted Solution

by:
MrPan earned 250 total points
ID: 10866952
Not exact code but to give you the idea

Sorry slightly wrong, I was deleting from the wrong database. Make sure you backup the databases first!!!!

CopyTable ("COMPANY","c:\old.mdb","c:\new.mdb")

----------------------------

Function CopyTable(TableName as string,DataSource as string, DataPathnew as string)

dim conn as adodb.connection
Set Conn = New ADODB.Connection

dim connNEW as adodb.connection
Set ConnNEW = New ADODB.Connection

Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
           "Data Source=" & DataSource & ";" & _
           "User Id=admin;" & _
           "Password=;"

ConnNew.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
           "Data Source=" & DataPathNew & ";" & _
           "User Id=admin;" & _
           "Password=;"

connNew.execute "Delete * From " & tableName
connNew.Close

        Ssql = "INSERT INTO " & TableName & _
        " IN '" & DataPathNew & "' SELECT " & TableName & ".* From " & TableName
        Conn.Execute (Ssql)
        conn.close
end Function
0
 

Author Comment

by:superbeast23
ID: 10868846
i know i didnt specify this in my opening, but is it possible to drop the table before copying the new table?  the reason i ask is that it is possible for the structure of the source table to change.  what would have to occur is the table with the new structure (i.e. new colums added) would be added to the central database there by deleting the old table.  both tables would still be named the same.
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question