I have an Access 2007 database on my local PC, and another one out on the network.
local: c:\mydatabase.accdb network: \server\share\publicdatabase.accdb
Both databases have 2 identical tables, let's call them Table1 and Table2
My process involves exporting data from a PICK database to a delimited text file, then importing it into Access.
Currently, I update the tables in my local db, then in Access I copy/paste the table from my local db to the network db. I'm hoping to do this via VBA.
I found the following code that would be used on the network db to clear a table and then 'pull' the update, but I need to run it from my pc to clear the network db table and then 'push' the update.
Dim AccessConn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Test Files\database.mdb")
AccessConn.Open()
Dim AccessCommand As New System.Data.OleDb.OleDbCommand("DELETE * FROM [Catlog]", AccessConn)
AccessCommand.ExecuteNonQuery()
AccessCommand.CommandText = "INSERT INTO [Table1] SELECT * FROM [MS Access;DATABASE=C:\Test Files\database.mdb;].[Table1]"
AccessCommand.ExecuteNonQuery()
AccessConn.Close()
Also if it's not too much trouble, how could I include a check to first make sure the network db is available to be updated? (not already open by other user)
Thank you!!
EDIT: this works so far:
With Access.DoCmd
.RunSQL "Delete FROM Table1 IN '\\server\share\publicdatabase.accdb'"
.RunSQL "Insert INTO Table1 IN '\\server\share\publicdatabase.accdb' SELECT * FROM Table1"
End With