Sub ExportToSecuredDB()
Dim strDestinationMDB As String
Dim dbsData As DAO.Database
strDestinationMDB = "C:\Passworded.mdb"
Set dbsData = DBEngine.OpenDatabase(strDestinationMDB, _
False, False, ";pwd=MyPassword")
'Export form
DoCmd.CopyObject strDestinationMDB, "Form1", acForm, "Form1"
'Export table
DoCmd.TransferDatabase acExport, _
"Microsoft Access", _
strDestinationMDB, _
acTable, _
"Table1", _
"Table1"
'Close secured database
dbsData.Close
Set dbsData = Nothing
End Sub
And here about the same, but for Excel:
How to import password-protected Excel spreadsheet
what if both of the db's are password protected
ReplyDeleteHi, same code should work also
ReplyDeletewhen I try to do this I get 2501 transferdatabase action was cancelled???
ReplyDeleteI had the same problem where transferdatabase did not work for the "CurrentProject" (forms, reports etc.) but worked for "CurrentData" (tables, queries etc.)
ReplyDeleteIf this happens between two MS Access databases, try the same export/import from the MS Access application (File->Get External Data->Import), it might give you some insight as to why the code is not working.
In my case, the source database was protected with a password and once I removed it (in the VBA window, Tools -> (project) Properties -> Protection tab) the transferdatabse code worked for forms, reports etc.
Hi Alex
ReplyDeleteThank you for your help.
I want to insert some records in to a table in a secured database, and before to do that, i want to delete and empty the table first.
best regards:
jack martin
Hi,
ReplyDeleteopen secured DB as above and then run:
dbsData.Execute "Delete * From MyTable Where ID=xxx"
Thanks, that's great! I tried it and it worked perfectly!
ReplyDelete