Module: JetDatabaseSecure32 in Category Access/Jet Databases : Database from Total Visual SourceBook

Modifying Access database settings under workgroup security using JRO and 32 bit versions of VBA and VB6.

This allows Microsoft Access to compact a database using different workgroup security than the one used to open Access.

Note: This code is not supported in the 64-bit version of Access 2010 or 2013 due to the use of the 32 bit library MSJRO.DLL. JRO has been deprecated after MDAC 2.7. JRO is not available on the 64-bit Windows operating system, and is not supported in the Microsoft Access 2007-2013 file format (*.accdb).

Procedure Name Type Description
(Declarations) Declarations Declarations and private variables for the modJetDatabaseSecure32 module.
CompactDatabaseBasicSecure Procedure Compact a secure database with no passwordCompact a secure database with no password.
DatabasePasswordChangeSecure Procedure Compact the database into a new database with the new password.
DatabasePasswordRemoveSecure Procedure Compact the database into a new database without a password.
DatabaseEncryptSecure Procedure Compact the database into a new database with encryption.
DatabaseDecryptSecure Procedure Compact the database into a new database without encryption.
CompactDatabaseGeneralSecure Procedure Compact the specified database.

Note: Access cannot compact the current database from VBA code. Set the database's Compact on Close option to do that. This code is not supported in the 64-bit version of Access 2010 or 2013 due to the use of the 32 bit library MSJRO.DLL. JRO has been deprecated after MDAC 2.7. JRO is not available on the 64-bit Windows operating system, and is not supported in the Microsoft Access 2007-2013 file format (*.accdb).
' Example of modJetDatabaseSecure32
' Note: Workgroup security only applies to MDB databases and not ACCDB or ADP formats
'       This code is not supported in the 64-bit version of Access 2010 or 2013 due to the use of the 32 bit library MSJRO.DLL.
'
' To use this example, create a new module and paste this code into it.
' Then run the procedure by putting the cursor in the procedure and pressing:
'    F5 to run it, or
'    F8 to step through it line-by-line (see the Debug menu for more options)

Private Sub Example_modJetDatabaseSecure32()
  ' Comments: Examples of using the modJetDatabaseSecure32 module to modify Access database settings under workgroup security, for VB6 and 32 bit versions of VBA.

  Const cstrDBName As String = "C:\Total Visual SourceBook 2013\Samples\Sample_Secure.mdb"
  Const cstrWorkgroup As String = "C:\Total Visual SourceBook 2013\Samples\Sample_Secure.mdw"
  Const cstrUserID As String = "Testuser"
  Const cstrPassword As String = "password"

  Dim strError As String
  Dim strPassword As String

  ' Compact database
  strError = CompactDatabaseBasicSecure(cstrDBName, cstrWorkgroup, cstrUserID, cstrPassword)
  If strError = "" Then
    MsgBox "Database successfully compacted", vbInformation
  Else
    MsgBox "Database could not be compacted: " & strError, vbInformation
  End If

  ' Encrypt DB

  If MsgBox("Are you sure you want to encrypt this database: " & cstrDBName & "?", vbYesNo + vbQuestion) = vbYes Then
    strError = DatabaseEncryptSecure(cstrDBName, cstrWorkgroup, cstrUserID, cstrPassword, "")
    If strError = "" Then
      MsgBox "Database successfully encrypted", vbInformation
    Else
      MsgBox "Database could not be encrypted: " & strError, vbInformation
    End If
  End If

  ' Decrypt DB

  strError = DatabaseDecryptSecure(cstrDBName, cstrWorkgroup, cstrUserID, cstrPassword, "")
  If strError = "" Then
    MsgBox "Database successfully decrypted", vbInformation
  Else
    MsgBox "Database could not be decrypted: " & strError, vbInformation
  End If

  ' Add Password

  strPassword = InputBox("Enter database password to add:")

  If MsgBox("Are you sure you want to add the database password '" & strPassword & "' to " & cstrDBName & "?", vbYesNo + vbQuestion) Then
    strError = DatabasePasswordChangeSecure(cstrDBName, cstrWorkgroup, cstrUserID, cstrPassword, "", strPassword)
    If strError = "" Then
      MsgBox "Password successfully added", vbInformation
    Else
      MsgBox "Password unsuccessfully added: " & strError, vbInformation
    End If
  End If

  strError = DatabasePasswordRemoveSecure(cstrDBName, cstrWorkgroup, cstrUserID, cstrPassword, strPassword)
  If strError = "" Then
    MsgBox "Password successfully removed", vbInformation
  Else
    MsgBox "Password unsuccessfully removed: " & strError, vbInformation
  End If

End Sub

Total Visual SourceBook The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.

Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!

Additional Resources

Total Visual SourceBook CD and Printed Manual

Microsoft Access/ Office 2016, 2013, 2010, and 2007 Version
is Shipping!

New features in Total Visual SourceBook for Access, Office and VB6

Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!


View all FMS products for Microsoft Access All Our Microsoft Access Products

Reviews

Reader Choice Award for MS Access Source Code Library
Reader Choice

"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."

Van T. Dinh, Microsoft MVP

SourceBook Info

Additional Info

Question

 

 

Free Product Catalog from FMS