Solved

Copying access tables to a central access database

Posted on 2004-04-19
5
217 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 Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

943 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

10 Experts available now in Live!

Get 1:1 Help Now