Results 1 to 2 of 2
  1. #1
    writeprivate is offline Advanced Access Coder
    Windows 10 Access 2021
    Join Date
    Feb 2023
    Posts
    42

    Using VBA to update linking to new passwrd protected backend

    I am trying to use an unbound combobox with afterupdate event to connect the front end to either a production or dev backend. I cannot seem to get this to work when the backend dbs are password protected. I have done lots of searcing and found various forum posts but none resolve for me.

    Could you have a look at this current code and see if any syntax issues pop out to you?

    The error i am getting is "Not a valid password" Error 3031.

    The password contains special chars, numbers, UC/LC letters. The passwords are valid when opening the front and back end natively. I have tried hardcoding the passwords into the code just to test if the issue is inputbox but same error. I have also tried using password variable as variant as well as string. Same error.



    Code:
    Private Sub cmbBackendSelection_AfterUpdate()    Dim selectedOption As String
        selectedOption = Me.cmbBackendSelection.value
    
    
        Dim backendFilePath As String
        Dim backendPassword As String
    
    
        Select Case selectedOption
            Case "Production"
                backendFilePath = "C:\Users\Documents\MICROSOFT ACCESS DBs\WM App\01_LIVE\WM_PRD_BACK.accdb"
            Case "Development"
                backendFilePath = "C:\Users\Documents\MICROSOFT ACCESS DBs\WM App\02_DEV\WM_DEV_BACK.accdb"
        End Select
    
    
        ' Prompt the user to enter the password for the backend
        backendPassword = InputBox("Enter the password for the backend database:", "Password Required")
    
    
        If Len(backendPassword) = 0 Then
            ' The user clicked Cancel or entered an empty password, exit the sub
            Exit Sub
        End If
    
    
        ' Update the links for all tables
        Dim db As DAO.Database
        Set db = CurrentDb
    
    
        Dim tdf As DAO.TableDef
        For Each tdf In db.TableDefs
            ' Check if the table is a linked table
            If tdf.Attributes And dbAttachedODBC Or tdf.Attributes And dbAttachedTable Then
                ' Update the link to the backend database with the password
                tdf.Connect = ";DATABASE=" & backendFilePath & ";PWD=" & backendPassword
                tdf.RefreshLink
            End If
        Next tdf
    
    
        Set db = Nothing
    End Sub


  2. #2
    writeprivate is offline Advanced Access Coder
    Windows 10 Access 2021
    Join Date
    Feb 2023
    Posts
    42
    EDIT - I should have noted that the code

    tdf.Connect = ";DATABASE="

    (adjusted to remove password entry) works perfectly where there is no password on the back end

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

Similar Threads

  1. Replies: 15
    Last Post: 03-25-2020, 01:25 PM
  2. Linking Tables from a password protected back end
    By rpeare in forum Programming
    Replies: 15
    Last Post: 12-16-2016, 03:47 PM
  3. Linking to a password-proteced backend
    By ascii in forum Programming
    Replies: 8
    Last Post: 03-18-2014, 06:56 PM
  4. Replies: 2
    Last Post: 11-05-2013, 03:59 AM
  5. linking table in a password protected database
    By bdaniel in forum Programming
    Replies: 1
    Last Post: 01-04-2012, 01:25 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