Results 1 to 2 of 2
  1. #1
    bdaniel is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    44

    linking table in a password protected database

    Trying to reconnect a link to a password protected database.



    Here is a portion of the the code from my sub procedure that I am using to make the connection:

    Public Sub CheckRegCode()

    Dim spath As String
    spath = CurrentProject.Path

    DoCmd.TransferDatabase acLink, "Microsoft Access", spath & "\Database1.accdb", acTable, "Copy of RegCodeImp", "Copy of RegCodeImp"

    This works fine except it asks for the password to open the database and I don't want the users to have the password, and there is no way in the TransferDatabase command to include the password for Access databases.

    After searching the internet for solutions, it appears that the only way to open the password protected database is using the opendatabase method.

    Below is my attempt at adding the necessary code to open the database so it can link. It requires using DAO, which I haven't used before. Was wondering if this looks correct?

    Public Sub CheckRegCode()

    Dim spath As String
    spath = CurrentProject.Path

    Dim db As DAO.Database
    Dim ws As DAO.WorkSpace
    Set ws = DBEngine.WorkSpaces(0)
    Set db = ws.OpenDatabase _ (spath & "Database1.accdb", _ True, True, "MS Access;PWD=MYPASSWORD")

    DoCmd.TransferDatabase acLink, "Microsoft Access", spath & "\Database1.accdb", acTable, "Copy of RegCodeImp", "Copy of RegCodeImp"

  2. #2
    bdaniel is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    44

    Smile

    The code below worked. I had to add the DeleteObject command because the TransferDatabase was adding a new table to the database instead of just linking the existing table.

    Public Sub CheckRegCode()

    DoCmd.DeleteObject acTable, "Copy of RegCodeImp"

    Dim spath As String
    Dim spathdb As String
    spath = CurrentProject.Path
    spathdb = spath & "\database1.accdb"

    Dim db As DAO.Database
    Dim ws As DAO.Workspace
    Set ws = DBEngine.Workspaces(0)
    Set db = ws.OpenDatabase(spathdb, True, True, "MS Access;PWD=MYPASSWORD")

    DoCmd.TransferDatabase acLink, "Microsoft Access", spathdb, acTable, "Copy of RegCodeImp", "Copy of RegCodeImp"

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Password protected form or report
    By mar_t in forum Access
    Replies: 11
    Last Post: 06-20-2013, 05:52 AM
  2. Replies: 9
    Last Post: 12-02-2011, 08:52 AM
  3. Open a password protected MDB/MDW
    By abcc14 in forum Security
    Replies: 8
    Last Post: 11-02-2011, 07:41 AM
  4. Replies: 4
    Last Post: 09-14-2011, 12:33 AM
  5. Password protected Switcboard buttons
    By mar_t in forum Access
    Replies: 9
    Last Post: 07-23-2011, 08:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums