Una famiglia di sistemi di gestione per database relazionali di Microsoft progettati per semplificare l'uso.
ciao Salvatore,
la routine che ti suggerisco cicla la collection tableDefs del currentDB, e le esporta in un db a in cui hai memorizzato il percorso della stringa StrPathDbBE.
nel loop viene controllato se nel db in cui esporti le tabella la tabella oggetto di trasferimento già esiste, se si, la funzione preposta gestisce l'errore e cancella la tabella esistente nel DB di destinazione e per poi esportatla nuovamente.
in questo modo avrai ad ogni esportazione le tabelle più aggiornate.
La cancellazione è la cosa più pratica per come ho inteso il tuo scenario, se vuoi nel caso di tabella esistente si potrebbe pensare a rinominarla.
copia/incolla il seguente codice in un modulo standard, personalizza il path contenuto nella variabile StrPathDbBE e richiama la sub transferTables:
Option Compare Database
Option Explicit
Private Const StrPathDbBE As String = "C:\Users\sandro\Desktop\belocale.accdb" '<<<<personalizza!
Public Sub transferTables()
On Error GoTo errorHandler
Dim tdf As dao.TableDef
Dim dbsBE As dao.Database
Dim dbsCU As dao.Database
Set dbsCU = CurrentDb
Set dbsBE = OpenDatabase(StrPathDbBE, False, False)
For Each tdf In dbsCU.TableDefs
If (tdf.Attributes And dbSystemObject) = False Then
If existsTable(tdf.Name, dbsBE) Then dbsBE.TableDefs.Delete (tdf.Name)
DoCmd.TransferDatabase TransferType:=acExport, _
DatabaseType:="Microsoft Access", _
DatabaseName:=StrPathDbBE, _
ObjectType:=acTable, _
Source:=tdf.Name, _
Destination:=tdf.Name
End If
Next
ext_errorLoadAccountHandler:
If Not dbsBE Is Nothing Then dbsBE.Close: Set dbsBE = Nothing
Set dbsCU = Nothing
Set tdf = Nothing
Exit Sub
errorHandler:
With Err
MsgBox "ERR#" & .Number _
& vbNewLine & .Description _
, vbOKOnly Or vbCritical
End With
Resume ext_errorLoadAccountHandler
End Sub
Private Function existsTable(ByVal strTable As String, _
ByVal ObjDestDB As dao.Database) As Boolean
On Error GoTo objHandler
Dim tdf As dao.TableDef
Dim bool As Boolean
bool = True
Set tdf = ObjDestDB.TableDefs(strTable)
exitErrTbl:
Set tdf = Nothing
Exit Function
objHandler:
bool = Not bool
Resume exitErrTbl
End Function
ciao, Sandro.
***** start Edit *****
solo se importi le tabelle è bene controllare l'esistenza di una tabella con lo stesso nome perché in export le tabelle vengono sovrascritte.
quindi il codice si semplifica cos' :
Option Compare Database
Option Explicit
Private Const StrPathDbBE As String = "C:\Users\sandro\Desktop\belocale.accdb" '<<<<personalizza!
Public Sub transferTables()
On Error GoTo errorHandler
Dim tdf As dao.TableDef
Dim dbsCU As dao.Database
Set dbsCU = CurrentDb
For Each tdf In dbsCU.TableDefs
If (tdf.Attributes And dbSystemObject) = False Then
DoCmd.TransferDatabase TransferType:=acExport, _
DatabaseType:="Microsoft Access", _
DatabaseName:=StrPathDbBE, _
ObjectType:=acTable, _
Source:=tdf.Name, _
Destination:=tdf.Name
End If
Next
ext_errorLoadAccountHandler:
Set dbsCU = Nothing
Set tdf = Nothing
Exit Sub
errorHandler:
With Err
MsgBox "ERR#" & .Number _
& vbNewLine & .Description _
, vbOKOnly Or vbCritical
End With
Resume ext_errorLoadAccountHandler
End Sub
***** end Edit *****