• open db from another db (Access 2000)

    • This topic has 12 replies, 5 voices, and was last updated 23 years ago.
    Author
    Topic
    #370918

    Open a database from another database
    is it possible to open a database protected with a password from another database? I want to build a code that opens a database,and supplies the necessary password,from another database.

    Viewing 1 reply thread
    Author
    Replies
    • #588166

      One option is to use DAO OpenDatabase method. Example:

      Function TestOpenPwdDatabase()
      On Error GoTo Err_Handler
      
          Dim ws As DAO.Workspace
          Dim db As DAO.Database
          Dim tbl As DAO.TableDef
          
          Set ws = DBEngine.Workspaces(0)
          Set db = ws.OpenDatabase("C:LOGIN.mdb", False, False, "MS Access;PWD=123XYZ")
          
          For Each tbl In db.TableDefs
              Debug.Print tbl.Name
          Next tbl
          
          db.Close
          ws.Close
      
      Sub_Exit:
          Set ws = Nothing
          Set db = Nothing
          Set tbl = Nothing
          Exit Function
      Err_Handler:
          MsgBox "Error " & Err.Number & ": " & Err.Description
          Resume Sub_Exit
      
      End Function
       

      You have to supply the optional Options and Read-Only arguments (can just use “False”) for OpenDatabase method or this won’t work, you’ll get error message “Not a valid password.” There’s no way I know of to provide password string if using TransferDatabase to import or link tables.
      HTH

    • #588181

      It depends on what you’re trying to do. Do you want to open an unprotected database and have it open a protected one so you can work in the protected one, or are you just trying to get data out of the protected one into the unprotected database?

      Keep in mind that the purpose of the password is to keep unauthorized persons from opening a database. If you create a means of getting into it without the password, you have just invalidated the protection on the other database. I personally wouldn’t do that.

      • #588192

        thank you for your reply.I am trying to get data out of the protected on into the unprotected database.I agrre with what you write about the protection it is just a special case where i need it and if you are interested i may send the explanation to you,however i am afraid i may be boring.How shall i proceed in my case to get data out of the protected database?

        Kind regards

        • #588319

          You can create a workspace to open a session on the other database and pass the username and password in there:

          Set wsp = DBEngine.CreateWorkspace(“”, strUser, strPwd, dbUseJet)

          This assumes that the database in question is a Jet database, of course. I’ve used strUser and strPwd to represent variables containing the username and password you need to pass in.

          The you open the remote database like this:

          Set dbs = wsp.OpenDatabase(“F:Protected.mdb”,False)

          You would substitute the correct path and filename for what I put in here.

          After that, you can open recordsets on the protected database and use them to write data into recordsets opened on the CurrentDb.

          • #588329

            A perfect answer. I feel obliged to express my gratitude since this was so important to me.
            Thank you very much !

          • #588356

            Charlotte,

            I’ve tried to find a work around for this situation a few times w/o success, until now. However, I’m still a little lost…..

            If the db I’m trying to EXPORT from is password protected, I would still need to know the password wouldn’t I? And If I did know the password, what’s the point in the code you offered? Or is your solution suggesting you wouldn’t need to know the user name and password? If the latter is correct, could you offer a little more explanation of the code you provided, as it seems to me that setting the variable would still require knowing the password in the first place.

            As you know, I’m a still a little dense when it comes to code so please forgive me for asking what might seem to be silly questions.

            Thanks in advance,

            • #588375

              The question was how to open a password protected database from another database, nothing else. To export from a database, you have to have it open and you wouldn’t be using code like this at all.

            • #588584

              Charlotte,

              I realize what the original question was, I however, was asking a similar question in regards to the password, I’m sorry if i didn’t make myself clear. This post was the first post I’ve seen close enough to my situation so I stuck my nose in and only asked you because you had the solution to the password issue. PASSWORD PROTECTED DB was what caught my eye. If I’m out of line, then I apologize.

              I was wanting to know if there was a way of EXPORTING objects from a password protected db w/o knowing the password. I know the code for exporting and importing, what I don’t know is how to do it when the password is unkown.

              And as always, thanks for your help.

              ps….the code you provided still seems to suggest the username and password must be known in the code. Just curious.

            • #588615

              Roberta,

              You aren’t out of line, but the code posted had nothing to do with an export, so your question confused me. Exports are done from within the database. That means you have to be able to open a database in order to Export, and that means you have to know the password in order to get there. There’s not much point in a password if anyone can come along and get around it. shrug

            • #588621

              Let me try this…if I may.

              In the forgein db I want to import objects from a password protected db, I don’t know the password, can this be accomplished?

            • #588754

              Well, *I* don’t know how. I suppose there might be a password cracker that would allow you to do it, but it is bad manners and can get you into legal trouble with whoever actually owns the protected db.

            • #588762

              Tut tut Roberta, but then again anything is possible.
              But as Charlotte says, be very careful.

    Viewing 1 reply thread
    Reply To: open db from another db (Access 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: