?
Solved

Copying access tables to a central access database

Posted on 2004-04-19
5
Medium Priority
?
222 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month8 days, 7 hours left to enroll

764 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