Minh Tiên > 16-01-15, 11:10 PM
Function ImportTableFromBackupDB(strTableList As String, ByVal FilePathName As String)
Dim i As Long
Dim sTableName As String
Dim dbs As DAO.Database
Set dbs = OpenDatabase(FilePathName, False, False, "Ms Access" & ";pwd=a123")
For i = 1 To DMax("[TableID]", strTableList)
sTableName = DLookup("[TableName]", strTableList, "[TableID]=" & i & "")
DoCmd.TransferDatabase acImport, "Microsoft Access", FilePathName, acTable, sTableName, sTableName
Next
Set dbs = Nothing
End Function
MTNQ > 17-01-15, 01:30 PM
Function ImportPasswordedDatabase()
' copies all tables from a passworded database into this database
Dim tdf As DAO.TableDef
Dim appacc As Object
Dim db As Database
Set appacc = CreateObject("Access.Application")
With appacc
.AutomationSecurity = 1
.OpenCurrentDatabase "C:\CopyFromDatabase.accdb", False, "YourPassword"
End With
For Each tdf In appacc.CurrentDb.TableDefs
If Left(tdf.Name, 4) <> "msys" Then
appacc.DoCmd.CopyObject "c:\CopyToThisDb.accdb", , acTable, tdf.Name
Else
'do nothing
End If
Next tdf
appacc.CloseCurrentDatabase
Set appacc = Nothing
' next line doesn't seem to work
'CurrentDb.TableDefs.Refresh
Application.RefreshDatabaseWindow
End Function
MTNQ > 17-01-15, 04:29 PM
Function ImportTableFromBackupDB(strTableList As String, ByVal FilePathName As String)
Dim i As Long
Dim sTableName As String
Dim dbs As DAO.Database
Set dbs = DBEngine.OpenDatabase(FilePathName, True, False, ";pwd=a123")
dbs.NewPassword "a123", ""
For i = 1 To DMax("[TableID]", strTableList)
sTableName = DLookup("[TableName]", strTableList, "[TableID]=" & i & "")
DoCmd.TransferDatabase acImport, "Microsoft Access", FilePathName, acTable, sTableName, sTableName
Next
dbs.NewPassword "", "a123"
dbs.Close
Set dbs = Nothing
End Function
Minh Tiên > 17-01-15, 05:25 PM
Minh Tiên > 17-01-15, 05:44 PM
MTNQ > 17-01-15, 06:23 PM
Minh Tiên > 17-01-15, 08:42 PM