Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically link tables using ADO and a password

Status
Not open for further replies.

Greyfleck

IS-IT--Management
Jun 2, 2008
61
GB
I have 3 dbs, forms, data and password. I have password protected data and password but now cannot open the databases.
I link the tables dynamically.
My code is
Code:
    datapathextra = "_data"

    mydot = InStr(1, datapath, ".")
    workpath = Left(datapath, mydot - 1)
    worklen = Len(datapath)
    workpath = workpath + datapathextra
    workpath = workpath + Right(datapath, worklen - (mydot - 1))
    Set db = OpenDatabase(datapath)
    

    db.TableDefs.Refresh
    table_count = db.TableDefs.Count
    For i = 0 To db.TableDefs.Count - 1
        If Left(db.TableDefs(i).Name, 4) <> "Msys" Then
            'check if name exists
            name_exists = False
            j = 0
 
                For j = 0 To mytablecount - 1

                    If db.TableDefs(i).Name = MyTables(j) Then
                        name_exists = True
                    End If

                Next j
                If name_exists = False Then
                    dbsource = db.TableDefs(i).Name
                    DoCmd.TransferDatabase acLink, "Microsoft Access", datapath, acTable, dbsource, dbsource
                End If
        End If

    Next i
    

    Set db = Nothing
what I now need is how to add the password ...

I have seen many examples and have tried most (incl. connectstrings) but cannot make it work.Any help greatfully appreciated.
 
led me to the following piece of code:
Code:
Public Function OpenPasswordProtectedDatabase(DBPath As String, _
Password As String) As Object

'Usage: Open Password protected database
'Parameters: DBPath: Full Path to Access Database
'Password: the Password
'returns the database, in it's open state if successful.
'Otherwise return value will evalute to nothing

On Error Resume Next
Dim db As DAO.Database

Set db = DAO.OpenDatabase(DBPath, False, False, _
    ";pwd=" & Password)

If Err.Number = 0 Then
    Set OpenPasswordProtectedDatabase = db
Else
    Set OpenPasswordProtectedDatabase = Nothing
End If
End Function

I am happy to change to DAO simply because this works.
This thread is now closed .......
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top