VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Open a password protected MDB using DAO or Data control or OLE automation

by ~DanDa311~ (4 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (4 Votes)

Open a password protected MDB using DAO or Data control or OLE automation

API Declarations
'sorry the first looked bad
'I found this code somewhere and the real author was Dalin Nie he deserves all the credit. I just thought that since it was so hard for me to find it i might as well make it easy to find for the rest of society

Rate Open a password protected MDB using DAO or Data control or OLE automation

'Use DAO:
Set MyDB = DBEngine.OpenDatabase(TheMDBNameWithFullPath,False,False,";Pwd=" & pwd)
Use Data Control
With Data1
.DatabaseName=App.Path & "\my.mdb"
.RecordSource="mytable"
.Connect=";Pwd=" & pwd
.Refresh
End With

Use OLE Automation
     Dim objAccess as Object
     '----------------------------------------------------------------------
     'This procedure sets a module-level variable, objAccess, to refer to
     'an instance of Microsoft Access. The code first tries to use GetObject
     'to refer to an instance that might already be open. If an instance is
     'not already open, the Shell() function opens a new instance and
     'specifies the user and password, based on the arguments passed to the
     'procedure.
     '
     'Calling example: OpenSecured varUser:="Admin", varPw:=""
     '----------------------------------------------------------------------
     Sub OpenSecured(Optional varUser As Variant, Optional varPw As Variant)
       Dim cmd As String
       On Error Resume Next
       Set objAccess = GetObject(, "Access.Application")
       If Err <> 0 Then 'no instance of Access is open
        If IsMissing(varUser) Then varUser = "Admin"
        cmd = "C:\Program Files\Microsoft Office\Office\MSAccess.exe"
        cmd = cmd & " /nostartup /user " & varUser
        If Not IsMissing(varPw) Then cmd = cmd & " /pwd " & varPw
        Shell pathname:=cmd, windowstyle:=6
        Do 'Wait for shelled process to finish.
         Err = 0
         Set objAccess = GetObject(, "Access.Application")
        Loop While Err <> 0
       End If

Download this snippet    Add to My Saved Code

Open a password protected MDB using DAO or Data control or OLE automation Comments

No comments have been posted about Open a password protected MDB using DAO or Data control or OLE automation. Why not be the first to post a comment about Open a password protected MDB using DAO or Data control or OLE automation.

Post your comment

Subject:
Message:
0/1000 characters