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

HELP. Working with Access Databases on Protected Media 2

Status
Not open for further replies.

thebernieb

Programmer
Jun 6, 2001
15
US
I can't seem to open MS Access .mdb files on write protected media like CD Roms or protected floppies. I'm trying to open them programmatically, but it gives me error messages. I've done just about all I can think about to get them to open, including setting the read only attribute to true in the file properties. Nothing seems to work. If anyone has any ideas, it would be greatly appreciated.

Bernie
 
Depends on what the mdb is trying to do when you open it. If there is code, macros or queries that are trying to change any data in the file then it will not work in readonly mode or on non-writable media. I have a database that renumbers a field when it opens and therefore doesnot work on a CD. It has to be re-programmed for that purpose.

Alex Middleton
 
Alex,

Thanks for the input. The specific problem I'm having now is that when trying to open the database programatically with the following code:
--------
Dim dbs As Database
Dim rst As Recordset

Set dbs = OpenDatabase("A:\DocControl.mdb", False, True)
Set rst = dbs.OpenRecordset("DOCUMENT")

MsgBox rst.Fields(0).Value
--------
I get and error message:

Run-time error '3050'
Couldn't Lock File.

Any ideas?





 
I cannot see anything in the code that would cause this error. Mention of the word 'lock' suggests to me that it is something to do with the record locking file (.ldb) that Access writes to disk every time an .mdb is opened. If the .mdb is on non-writable media then this file cannot be written and could cause the error.

When I put a database onto a CD, usually for read-only access anyway, I convert it to an .mde which does not seem to cause the same problem, althoug it still writes an .ldb to disk on opening. Beyond this I am a bit stumped. Alex Middleton
 
Alex,

I figured it out. There seems to be a few steps one must take in order to make this work. First of all, you've got to go into the database and set up an account (I used the Admin) with Open Exclusive checked in the rights for the database object. Then you have to change the database file's (*.mdb) read only file attribute - it must be set to true. Then in the code, you must first establish a workspace:

Set wrk = CreateWorkspace ("myWorkSpace","Admin")

---
I think that's the right syntax, but essentially you are just telling the database to expect a given user with a given password. Then when you set the database object:

Set dbs = wrk.OpenDatabase (DatabasePathandsuch,true,true)

---

This ensures that you're opening it up read only and exclusive. If you don't open it exclusively, Access tries to write a lock file and generates an error because you can't write a lock file onto protected media! So there. Woo! What a pain huh? Thanks again for your help.

Bernie
 
Thanks for the feedback. That will be useful to know for the future. Alex Middleton
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top