Reshmi mohankumar
Registered User.
- Local time
- Today, 06:00
- Joined
- Dec 5, 2017
- Messages
- 101
Hi,
I wish to update my present working securedDB with structure updated secured DB by using below code.
But there is no response/ error when excutes. Even tried by removing password to DB at source.
If password exists then error 3031 appearing at OpenDatabase.
Any helpful suggestions will be accepted.
I wish to update my present working securedDB with structure updated secured DB by using below code.
But there is no response/ error when excutes. Even tried by removing password to DB at source.
If password exists then error 3031 appearing at OpenDatabase.
Any helpful suggestions will be accepted.
Code:
Sub CopyTablesBetweenDatabases()
Dim sourceDB As DAO.Database
Dim targetDB As DAO.Database
Dim tbl As DAO.TableDef
Dim sourceTableName As String
Dim targetTableName As String
' Set the source and target database file paths
Dim sourceDBPath As String
Dim targetDBPath As String
sourceDBPath = CurrentProject.Path & "\structure\HardwareBE.accdb"
targetDBPath = CurrentProject.Path & "\HardwareBE.accdb"
' connect = "[;DATABASE=" & sourceDBPath & ";PWD=rmk3200125]"
' Open the source and target databases
Set sourceDB = OpenDatabase(sourceDBPath)
Set targetDB = OpenDatabase(targetDBPath)
' Loop through all tables in the source database
For Each tbl In sourceDB.TableDefs
sourceTableName = tbl.Name
targetTableName = tbl.Name
' Check if the table name already exists in the target database
If Not TableExists(targetDB, targetTableName) Then
' Copy the table structure and data
MsgBox "Start"
DoCmd.TransferDatabase acImport, "Microsoft Access", targetDBPath, acTable, sourceTableName, targetTableName, 1
MsgBox "End"
End If
Next tbl
' Close the databases
sourceDB.Close
targetDB.Close
' Release the database objects
Set sourceDB = Nothing
Set targetDB = Nothing
End Sub
Function TableExists(db As DAO.Database, tableName As String) As Boolean
' Check if a table exists in the specified database
On Error Resume Next
TableExists = Not (db.TableDefs(tableName) Is Nothing)
On Error GoTo 0
End Function