Just re-read your post and I missed of some of the code that you may need.
Feel free to use the code or bits of it I you want.
In my case each laptop has 2 DB’s. NewVentureMDB and MerchantMDB
I need to ensure that the latest data is available to field staff (they use
the MerchantMDB to make sales). As you can see the code below checks the
NewVenture exists – if it does it deletes it. Then a new copy of NewVenture
is imported. The 3 tables that are needed in Merchant tblBookings –
tblClients - tblEvents are deleted then imported from the new copy of
NewVenture. It’s not really the DB, I need to import. It’s that data in 3
tables. (and relationships need to stay in place).
Hope that makes sense. I have done this to ensure the field staff always
have the most up to date bookings details. - You can’t sell anything to
someone who doesn’t exist ??
frmMerchanttimerWait s just a popup that runs for 15 seconds to tell them to
leave things alone.
This is copied from a form on a test laptop so you will need to change the
names and paths to what you need.
Private Sub cboImport_Click()
'Open form with timer event close to tell staff not to do anything'
DoCmd.OpenForm "frmMerchanttimerWait", acNormal, "", "", , acNormal
'Check NewVenture.MDB exists'
Dim strOldPathName As String
Dim strNewPathName As String
myfile = Dir("C:\Documents and Settings\UK Outdoor Pursuits\My
Documents\UKOP_stuff\NewVenture.mdb")
'If it does delete it'
If myfile <> "" Then
Kill "C:\Documents and Settings\UK Outdoor Pursuits\My
Documents\UKOP_stuff\NewVenture.mdb"
'Then reimport NewVenture.MDB'
strOldPathName = "E:\NewVenture.mdb"
strNewPathName = "C:\Documents and Settings\UK Outdoor Pursuits\My
Documents\UKOP_stuff\NewVenture.mdb"
DBEngine.CompactDatabase strOldPathName, strNewPathName
Else
'If it didn't exist then import NewVenture.MDB from E drive onto C drive'
strOldPathName = "E:\NewVenture.mdb"
strNewPathName = "C:\Documents and Settings\UK Outdoor Pursuits\My
Documents\UKOP_stuff\NewVenture.mdb"
End If
'If tables exisit - delete them'
Dim db As Database, tdf As TableDef
Set db = CurrentDb()
For Each tdf In db.TableDefs
If tdf.Name = "tblBookings" Then
DoCmd.DeleteObject acTable, "tblBookings"
End If
If tdf.Name = "tblClients" Then
DoCmd.DeleteObject acTable, "tblClients"
End If
If tdf.Name = "tblEvents" Then
DoCmd.DeleteObject acTable, "tblEvents"
End If
'Reimport tables from newly imported DB on C drive'
Next
DoCmd.TransferDatabase acImport, "Microsoft Access", "C:\Documents and
Settings\UK Outdoor Pursuits\My Documents\UKOP_stuff\NewVenture.mdb",
acTable, "tblBookings", "tblBookings", structureonly:=False
DoCmd.TransferDatabase acImport, "Microsoft Access", "C:\Documents and
Settings\UK Outdoor Pursuits\My Documents\UKOP_stuff\NewVenture.mdb",
acTable, "tblClients", "tblClients", structureonly:=False
DoCmd.TransferDatabase acImport, "Microsoft Access", "C:\Documents and
Settings\UK Outdoor Pursuits\My Documents\UKOP_stuff\NewVenture.mdb",
acTable, "tblEvents", "tblEvents", structureonly:=False
End Sub
Hope all this helps.
-
Wayne
Manchester, England.