How do I compact and repair a database with a password

Clive Beaton
Clive Beaton used Ask the Experts™
on
I'm trying to compact and repair a password protected database with the following code:

Public Sub Compact()
   Dim CurrentFile As String, BackupFile As String
   On Error GoTo 0
   CurrentFile = "C:\CAV3\Database1.accdb"
   BackupFile = "F:\Database1.accdb"
   If Dir(BackupFile) > "" Then
      Kill BackupFile
   End If
   Application.CompactRepair CurrentFile, BackupFile, True
   Exit Sub
   
End Sub

How do I change it to supply the password?

Thanks in advance.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
look at DBEngine.CompactDatabase Method

http://msdn.microsoft.com/en-us/library/office/ff844821(v=office.15).aspx

DBEngine.CompactDatabase CurrentFile, BackupFile, ";pwd=password", , ";pwd=password"
Clive BeatonAccess Developer

Author

Commented:
Perfect.  Thank you.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial