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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Link fe to PWD protected be via VBA!

Status
Not open for further replies.

TheAceMan1

Programmer
Sep 23, 2003
11,174
0
36
US
Howdy All! . . .

How can I link an access frontend to a password protected access backend [blue]thru VBA?[/blue]

The be data can come from four different be DB's (four copies of the be in different locations, just different data! . . .

I can do this thru the [blue]Linked Table Manager[/blue], however a need to switch backends thru VBA has brought me to this issue . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Check out the

OpenDatabase Method

in the VBA Help file. You can pass the password in that.


Bob Larson
A2K,A2K3,A2K7,SQL Server 2000/2005,Crystal Reports 10/XI,VB6, WinXP, and Vista
Free Quick Tutorials and Samples:
 
I have not done this for a while so I thought I would play with it.

I created a simple password protected DB

I created another DB with a form and command button to run through the module that I added.
(The text from the module is a modified version from a VB6 module)

Here is the module information
Code:
Option Compare Database


Function GetRS(strSql As String) As Recordset
    'Get the database name from the .ini file

    Dim db As Database
    Dim rs As Recordset
    Dim dbName As String
    
        dbName = CurrentProject.Path & "\PasswordProtectedDB.mdb"
    
    'Check to make sure the database is there
    'If Len(Dir(DBName)) < 1 Then
    '    CreateDB
    'End If
    'Debug.Print strsql
    'Stop
    
    Set db = OpenDatabase(dbName, False, False, ";pwd=password;")

    Set GetRS = db.OpenRecordset(strSql, dbOpenSnapshot)
    
End Function

Here is how I call the recordset from the click event of the command button

Code:
Option Compare Database

Private Sub cmdGo_Click()
Dim rs As Recordset
Dim strSql As String

strSql = "SELECT LastName, FirstName FROM tNames"

Set rs = GetRS(strSql)

While Not rs.EOF
    MsgBox "This is: " & rs.Fields("LastName").Value & ", " & rs.Fields("FirstName").Value
    rs.MoveNext
Wend
Set rs = Nothing
End Sub


 
Howdy CaptainD . . .

I don't want to open the backend. I just want to link the backend tables to the frontend! . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
To All . . .

Problem solved (I knew I had the syntax somewhere in my library). The following is just the idea of the syntax:
Code:
[blue]   Dim db As DAO.Database, tdf As DAO.TableDef
       
   Set db = CurrentDb
   Set tdf = db.TableDefs("[purple][b]TableName[/b][/purple]")
      
   With tdf
      [green]'Use line below for non-password protected backend[/green]
      .Connect = "MS Access;DATABASE=" & NewPath
      [green]'Use line below for password protected backend[/green]
      .Connect = "MS Access;DATABASE=" & NewPath & ";PWD=[purple][b]yourpassword[/b][/purple]"
      .RefreshLink
   End With
   
   Set tdf = Nothing
   Set db = Nothing[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
If I recall, all this does is pull in the records requested and does not leave it "open" when done.

You could pass the name of the database you want along with the SQL string and would not need to link.

Note: This came from a VB 6 program so there was no "Link" capability.




 
CaptainD . . .

In my case it has to do with [blue]split Db[/blue], which is normally done when the Db is to reside on a network.

Have a look here Why Split a Database?

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
To Ace-Man

I have a similar problem, and was wondering where you need to put the code. Can it run once on startup, up do you need to include it anytime you open a form or run a query using the linked tables?

Thanks

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top