passing a password to an access object

Posted on 1999-06-30
Medium Priority
Last Modified: 2010-05-02
Is it possible to pass a password to an access object
(dim OAccess as Access.application)
I'm using it to print reports, and I don't want anyone to have access to the database.
Question by:scottd1978
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 1521118

        Option Explicit
          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
          '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
          End Sub

Author Comment

ID: 1521119
This code still asks for a password when I try to open the database.
LVL 70

Accepted Solution

Éric Moreau earned 150 total points
ID: 1521120
Try this:

Private Declare Function ShowWindow _
                Lib "user32" _
                (ByVal hwnd As Long, _
                 ByVal nCmdShow As Long _
                ) As Long
Private Const SW_HIDE = 0

Dim db As Database
Dim lngRet As Long
Dim objAccess As Access.Application

    Set objAccess = New Access.Application
    'Hide Access
    lngRet = ShowWindow(objAccess.hWndAccessApp, SW_HIDE)
    With objAccess
        'Open the database
        Set db = .Application.DBEngine.Workspaces(0).OpenDatabase("YourDatabasePath", 0, False, ";pwd=YourPassword")
        .OpenCurrentDatabase "YourDatabasePath", False
        Set db = Nothing
        .DoCmd.OpenReport "ReportName", acViewNormal
    End With


Author Comment

ID: 1521121

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question