Results 1 to 8 of 8
  1. #1
    yann
    Guest

    protected acces db and Office automation

    Hi,

    I try to connect to a protected access db from within Word 97

    here is the code :

    Set ObjAcc = CreateObject("Access.Application")
    ObjAcc.OpenCurrentDatabase "C:mydb"

    the problem is that
    the ObjAcc.OpenCurrentDatabase "C:mydb" instruction does not allow to give the user name and password to Access
    [img]/w3timages/icons/frown.gif[/img]

    any idea ??

  2. #2
    Scott A
    Guest

    Re: protected acces db and Office automation

    What are you trying to do with the open database?
    If you just want to pull data from the db, you probably want to use DAO or ADO to connect to the database, which both allow you to specify a user id and password.

  3. #3
    yann
    Guest

    Re: protected acces db and Office automation

    Hi,

    I am trying to put data from Word into the access db including the word file itself in an OLE field which can be done (as far as I could find now) only using a form field property.

    I found this in the MS KB that seems to fit to what I am trying to do (although it seems painful) :
    ------------------------------------------------------------
    Global Const AccessPath = "C:Program FilesMicrosoft OfficeOfficemsaccess.exe"
    Global Const AccSecurdb = "M:InformatiqueFonctionnelCommunrefdoc.mdb"

    Sub openSecuredAccessdb()
    Dim ObjAcc As Access.Application
    Dim cmd As String
    Dim sUser As String, sPw As String

    sUser = "toto"
    sPw = "titi"

    On Error Resume Next
    Set ObjAcc = GetObject(, "Access.Application")
    If Err <> 0 Then
    cmd = AccessPath & " /nostartup /user " & sUser & " /pwd " & sPw
    Shell pathname:=cmd
    Do
    Err = 0
    Set ObjAcc = GetObject(, "Access.Application")
    ObjAcc.OpenCurrentDatabase AccSecurdb, False
    ' do what you want to do
    'faire quelque chose
    Loop While Err <> 0

    Else
    ' ask the user to close Access
    ' on aura int

  4. #4
    DAW
    Guest

    Re: protected acces db and Office automation

    I know you can do this using ADO (you set the 'Jet OLEDDB:System database' property of the Connection object to the relevant workgrop file and then pass the UserId and Password to the Open method of the Connection object).

    I wasn't aware that this could be achieved using DAO though. In the past I have had to shell out to a new instance of Access (you can then use the /user and /password switches) and then use GetObject() to work with it.

    Please enlighten me if you know how to achieve this in DAO. (I.E open an Access database secured with full User-Level security)

    Thanks

    Dave.

  5. #5
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: protected acces db and Office automation

    Hi,
    The CreateWorkspace method allows you to specify a user name and password - is that what you were after?
    Regards,
    Rory

    Microsoft MVP - Excel

  6. #6
    DAW
    Guest

    Re: protected acces db and Office automation

    I don't think so. You can pass in a username and password, but they must be present in the current Workgroup. You cannot (or so I believe) open another database that has it's own MDW file with it's own names and passwords.

    If you have done this, then please publish the code.

    Thanks.

    Dave.

  7. #7
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: protected acces db and Office automation

    I can't say I've ever done it - there are only 15 people in my company so more than one workgroup would be a bit excessive. I don't suppose you can set the DBEngine.SystemDB property if you're already in an Access app? I can't think of another way to do it. Maybe someone else can confirm or deny whether it can be done.
    Regards,
    Rory

    Microsoft MVP - Excel

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: protected acces db and Office automation

    The KB code is taking care of this with the lines:

    cmd = AccessPath & " /nostartup /user " & sUser & " /pwd " & sPw
    Shell pathname:=cmd

    What that is doing is shelling to the Access executable using the username and password for that database. You could extend this by including the /wrkgrp switch and the full path and filename of the mdw for that workgroup.

    Once you've passed the command line arguments, your OpenCurrentDatabase should work with the protected MDB...as long as you got all the arguments right. I dont' think you would be able to do this from Access itself, but it should work from Word.
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •