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

I wrote the following codes to link

Status
Not open for further replies.

HomeALone

Instructor
Jul 20, 2001
110
US
I wrote the following codes to linked a table from another Access database.

Dim db as DAO.Database
Dim TD as TableDef
Set db = CurrentDb
Set TD = db.CreateTableDef("TableNameAfterLink")
TD.Connect = ";Database=" & "G:\folder\target.mdb" 'Path to target database
TD.SourceTableName = "TableNameInExternalDatabase"
db.TableDefs.Append TD
Set TD = Nothing
db.close

And use the following codes to remove the linked table reference afterward:

Set db = CurrentDB
Set TD = db.TableDef("NameOfLinkedTable")
db.TableDefs.Delete "NameOfLinkedTable"
Set TD = Nothing
db.close

I works great. Now, how can I modify the code to link to a password protected database? Thanks!


 
Looks just like the code I wrote and posted in Thread thread705-488486. Hmmm...? The additional parameters for UserID(UID) AND Password(PWD) have been added. The red code is where you would put the actual userid and passwords. They should just be typed in and NOT surrounded by quotes.
TD.Connect = ";Database=" & "G:\folder\target.mdb" & ";UID=userid;PWD=password;"

If you want to use a variable for both of the fields then the following could be used:
TD.Connect = ";Database=" & "G:\folder\target.mdb" & ";UID=" & vUserID & ";PWD=" & vPassword & ";"

Both the vUserID and vPassword can hold data from a table or the current userID. This allows any number of authorized users to be able to make the connection to the external database.

I think this should help you and your students.

Bob Scriver
 
hmmmmmmmmmm ... mmmmmmmmmmmmmm,

As explicitly shown, the switching could be hazzardous if applied to a 'consolidated' .MDB, or even a slpit one where all users 'share' the same front-end from a server. In these situations, the re-mapping would apply to the shared .MDB, and thus when the change takes place, it is 'left' in the shared copy. Since different Users may have different 'mapping', the use of the shared path may direct some users to incorrect (or even non-existant) locations. A better (but far from perfect) soloution would use "URL" addressing. At least in that case, the resolved path should always exist.

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Hey Bob,

You are right! it is absolutely your work and thank you for the original work and added features-user and password. I will mention your name, Bob Scriver,to my students
for the credit.

My next question on this: Can the link be READ only? No change allowed. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top