Solved

Copying access tables to a central access database

Posted on 2004-04-19
5
216 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now