I use a database connection string as below and my program work fine.

Public Function initdb()
Set ws = DBEngine.Workspaces(0)
Set db = ws.OpenDatabase(App.Path & "\Masterfile.mdb")
Set rs = db.OpenRecordset("Detail", dbOpenTable)
max = rs.RecordCount
Exit Function
End Function
But now I lock the msaccess table ie. Masterfile.mdb with password in order to prevent anyone opening the table and change data inside not through the program, how do I change the connection string so that my code would still work with the protected database.

Any help or suggestion would be highly appreciated.


What version of DAO are you using?

I am not sure about the DAO version stuff, what i know is that I use ms access 2002, Office XP, does this help ? like i mention before i need to lock the access table so that the table can only be open through the program. I can lock the database with password, but how do I change/modify the code to open the access table.


Open your Database like this :

Set db = ws.OpenDatabase(App.Path & "\Masterfile.mdb", False, False, ";pwd=MyPassword")


'add Microsoft DAO 3.5 in the project from Reference
Dim myDb as Database
Dim mySet as Recordset
'write in Form Load event
Set myDB=Open Database("Path of the .mdb")
Set Myset=myDb.Open Recordset("TableName",dbopendynaset)

' if you want to display in some text box
' and so on.

mesgbox("Record Updated")

Try this, it may helps you

Hi Veena,

It sure works now, thanks for your line. Now I can protect the msacess table with the password.