Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441

    Linking Tables from a password protected back end

    I swear I had this code working earlier this morning but now every time it tries to link the external table I get prompted for a password even though the connection to the back end database is open. Anyone see where I'm going wrong?




    Code:
    Dim fs
    Dim sSource
    Dim db As Database
    Dim tdf As TableDef
    
    
    'On Error GoTo ERRHANDLER
    Set fs = CreateObject("Scripting.filesystemobject")
    sSource = CurrentProject.Path & IIf(Right(CurrentProject.Path, 1) <> "\", "\", "") & "Data.accdb"
    If fs.FileExists(sSource) Then
        Set db = OpenDatabase(sSource, False, False, "MS Access;pwd=" & fldPW & "")
        For Each tdf In db.TableDefs
            If Left(tdf.Name, 4) <> "MSys" Then
                If DCount("[Name]", "Msysobjects", "[Name] = '" & tdf.Name & "'") = 1 Then
                    CurrentDb.Execute "DROP TABLE " & tdf.Name
                End If
                Debug.Print tdf.Name
                DoCmd.TransferDatabase acLink, "Microsoft Access", sSource, acTable, tdf.Name, tdf.Name
            End If
        Next tdf
        db.Close
        Set db = Nothing
    Else
        MsgBox "This database expects the back end and the front end in the same folder" & vbCrLf & vbCrLf & "The back end database was not found", vbOKOnly, "ERROR Connecting to Back End"
        Exit Sub
    End If
    Set fs = Nothing

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    There's no reason to use code. Just link the table via ODBC with the password. No code failures.

  3. #3
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    You are trying to link to tables in an external database, right? You should be looking at tabledefs in THIS database, not the external one.

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    I do not need an overly simplistic solution. I am not doing this for spurious reasons.

    My back end is password protected.
    The front end will be in the same folder as the back end.
    Each time the database is opened there will be *no* linked tables
    I want this code to examine the tabledefs in the external (password protected) database and link all tables in that external database to the current database.
    Part of the database closing procedure is to remove all links so there is no data in the front end if it's opened without a proper password.

  5. #5
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    This code is working for me. I don't see where your password is set, did you debug thru the code and see if fldPW has a value when you run this?

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    it does I can see it when I do a debug.print fldpw

    that's what's driving me crazy

  7. #7
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    ....
    I just went back to it, did not change the code in the slightest and it worked....

  8. #8
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Can you open the back-end normally and view the data? If you hard-code the fldPW to the actual password does that fix it?

  9. #9
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    And I closed it and re-opened it and it prompts for the password again on each table... this is really weird behavior.

    Even with a hard coded password it still prompts me. I can't figure out what's allowing it to work sometimes and other times not work.

    I'm enclosing a sample database because this is driving me crazy.

    FrontEnd.zip

    the back end password is: $3cR3T!!
    Last edited by rpeare; 12-16-2016 at 11:13 AM. Reason: Db Example

  10. #10
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    What about the back-end?

  11. #11
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    The back end should be in that zip file did it only contain the front end?

  12. #12
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    I was using my Downloads folder and getting the same result as you. I copied it to My Docs and it works!

  13. #13
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    It has both worked and not worked from a folder on my desktop
    I have also copied it to c:\testfolder\ and it still prompts for a password with each table

  14. #14
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    I wouldn't think that c:\testfolder would work, c drive sometimes has strange permission settings.

  15. #15
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    I found the problem

    Code:
    If DCount("[Name]", "Msysobjects", "[Name] = '" & tdf.Name & "'") = 1 Then
         CurrentDb.Execute "DROP TABLE " & tdf.Name
    End If
    This section of code is getting confused between doing my dcount on the foreign database or the local database. I've modified the code and all is well.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 06-03-2016, 03:58 AM
  2. Linking Tables to Sql Password question
    By crimedog in forum Import/Export Data
    Replies: 2
    Last Post: 01-21-2016, 09:03 AM
  3. Re-Link back-end tables when password protected
    By RMittelman in forum Security
    Replies: 8
    Last Post: 06-19-2015, 11:03 AM
  4. linking table in a password protected database
    By bdaniel in forum Programming
    Replies: 1
    Last Post: 01-04-2012, 01:25 AM
  5. Replies: 4
    Last Post: 09-14-2011, 12:33 AM

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