How can i link programaticaly to the table/tables form School.mdb without
having the popup form who ask for a password?
The user is prompted for a password for a very good reason. If the user
doesn't know the password, then the user isn't authorized to link to a table
in the password-protected database. However, there are times when the
database tables need to be relinked by a user who doesn't have the password.
Unfortunately, that means that the password will be sitting in the VBA Editor
for any user who cares to look. Therefore, I urge you to use the code only
for an MDE file, and as soon as the MDE file is created, delete the password
in the source code in the original MDB file.
To link to the StudentsMaster table in the School.mdb database from the
current database, try:
Public Sub linkTblInDBwPswd()
On Error GoTo ErrHandler
Dim db As Database
Dim tbl As TableDef
Dim sPath As String
Dim sTblName As String
Dim sLinkedTblName As String
Dim fOpenedDB As Boolean
sPath = "C:\School\School.mdb"
sTblName = "StudentsMaster"
sLinkedTblName = "Stud"
Set db = CurrentDb()
fOpenedDB = True
Set tbl = db.CreateTableDef(sLinkedTblName, dbAttachSavePWD, _
sTblName, ";Database=" & sPath & ";Pwd=MyPswd")
db.TableDefs.Append tbl
Exit Sub
CleanUp:
Set tbl = Nothing
If (fOpenedDB) Then
db.Close
fOpenedDB = False
End If
ErrHandler:
MsgBox "Error in linkTblInDBwPswd( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear
GoTo CleanUp
End Sub
.. . . where MyPswd is the database password.
HTH.
Gunny
See
http://www.QBuilt.com for all your database needs.
See
http://www.Access.QBuilt.com for Microsoft Access tips.
(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.