Share this Page URL

Chapter 19. Using External Data > Refreshing and Removing Links - Pg. 525

Using External Data 525 Working with Passwords When working with passwords, you probably won't want to hard-code the password into your ap- plication because it defeats the purpose of placing a password on your database. In Listing 19.9, the database's password is included in the code, allowing the link to be made to the secured table without any password validation. Example 19.9. Embedding a database password in code. Sub LinkToSecured() Dim db As DATABASE Dim tdf As TableDef Set db = CurrentDb Set tdf = db.CreateTableDef("tblSecuredTable") tdf.Connect = ";Database=" & APPPATH & "\secure.mdb;PWD=alison" tdf.SourceTableName = "tblClients" db.TableDefs.Append tdf End Sub Although an invalid password results in a message such as the one in Figure 19.10, it is best to require the user to supply the password at runtime. In Listing 19.10, the password argument is left blank, which causes the user to be prompted for a database.