Get pass a password-Excel to Access

Posted on 2006-03-28
Last Modified: 2010-04-07
I this code in excel, How do I get pass the "password".

At this point, click the command button and it open Access and bypass the password and go directly to a form.

'opens access
    ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="Volume.mdb", _
    Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
    Set App = GetObject("\\Dtcnas-ilsp002\mandatory\Analysts - Working Files\Carol\Demo\Volume.mdb;pwd=OPPs;")
App.Application.DoCmd.RunMacro "Macro2CloseSwitchboard"
App.Application.DoCmd.openform "Form"

 Any help would greatly be appreciated!

Question by:ca1358
    LVL 84

    Accepted Solution

    Generally you must pass the db password via  commandline switch. Perhaps this code snippet will help (came from here:

    This uses ULS, but you can alter the commandline switches to insert the db password. You may not need the /user switch either, so you may need to comment out that line.

       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
    LVL 15

    Expert Comment


    Author Comment

    still trying to figure this out!!

    Author Comment

    Got this work, thank you all for your help!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    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…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now