Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Can Open Read-only Database Manually, but not via VBA

Posted on 2004-09-16
8
Medium Priority
?
869 Views
Last Modified: 2006-11-17
Hello All,

Trying to access a read-only A2K database via a NT network using VBA. No protection/privilege  problems when I manually open the DB, but I am unable to get beyond an "Could not Lock File" error using VBA.

The DB is read-only and  does not have a password.

I am invoking the following code:

  Dim dbReadOnly As DAO.Database
  ...
  ...
  ...
  Set dbReadOnly = OpenDatabase(strPATH, vbFalse, vbTrue)

Any ideas?

Thanks in advance.

Deb
0
Comment
Question by:DMV
  • 3
  • 3
  • 2
8 Comments
 
LVL 12

Expert Comment

by:pique_tech
ID: 12081135
I have tried unsuccessfully to duplicate your problem using the following code:

Public Sub TestOpenDB()

Dim db As DAO.Database
Dim td As DAO.TableDef

Set db = OpenDatabase("C:\MyDBName.mdb", vbFalse, vbTrue)
For Each td In db.TableDefs
    Debug.Print td.Name
Next
db.Close
Set td = Nothing
Set db = Nothing

End Sub

I have had the target database set unrestricted, read-only, exclusive, and default record locking set to all records, yet each time the Immediate window filled with the names of my tables.  Is it possible that the database is set to open with Exclusive access and that someone else has it open?  That's the only possibility that makes any sense to me, though it also occurs to ask whether you have the proper security on the drive/folder where the database is located.

Scratching head.  Hope this helps, or that someone else has more, better ideas.
0
 
LVL 12

Expert Comment

by:pique_tech
ID: 12081154
In particular, you'd have to have file create rights in the directory or Access won't be able to create the .ldf file.  However, I'd think you'd have the same problem opening the database manually if that were the case.
0
 

Author Comment

by:DMV
ID: 12081246
Hello pique-tech,

This seems to be a networking issue; I am able to gain access to the database on my local drive as well.  Again, manual access works fine.

Thanks for your efforts.

Deb
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:pique_tech
ID: 12081299
Then I'd certainly investigate the security of the folder where the db is located.  Obviously, if Access cannot create the .ldf file (the locking file), it won't be able to get a lock on the database.
0
 

Author Comment

by:DMV
ID: 12081337
Obvious, or not I am simulating a network drive, using a CD-ROM, and it behaves the same as the network drive -- manual access, no problem, VBA ~ zilch.

From this test, the question arises ~ why can I manually access a db on CD-ROM when I most certanly cannot not create the .ldf on that media.

Hopefully, someone else can further enlighten me about this perplexing issue.

Deb
0
 
LVL 2

Accepted Solution

by:
ApK earned 1500 total points
ID: 12081392
I have reproduced this.

As mentioned above, if the folder containing the mdb file does not have write permissions, then access can't create the lock file.

Interestingly, if you open the mdb directly from the same folder (still without write permissions), Access does not create the LDB file (cos it can't), but does not give an error.

In other words, using VBA throws an error, using Access application does not.

So why the difference? I don't know.

However, if you change the 'options' argument to True (i.e. 'exclusive mode'), then it works.

Set dbReadOnly = OpenDatabase(strPATH, True, vbTrue)

It would appear that opening in exclusive mode means no LDB is required, and hence no error.

Cheers,
Andrew.
0
 

Author Comment

by:DMV
ID: 12081552
Thanks Andrew.

Actually, whenever I access the DB on the CD-ROM, it creates a default lock file, System.ldb in C:\Program Files\Common Files\System.

Just when I think MS Access can not possibly be more confusing and/or counter intuitive....  

If I understand you correctly ~ I should set the exclusive-access mode to TRUE to inhibit lock file creation, although I want to open the database for share-access.  What is wrong with this picture?

You are absolutely right,  it does work -- I hope someday, if I am very, very  good the Access Gods might just reveal the "why."

Thanks again for your intervention; I am sure I would have spent hours on this issue.

Best wishes,
Deb
0
 
LVL 2

Expert Comment

by:ApK
ID: 12081631
For shared access, the lock file has to be in the same folder (so that everyone can find it in one place - and 'share' it). So that part makes sense.

I don't know why then it would work in the exclusive case (because to be exclusive, you need to prevent others from modifying it, and therefore you need to write a lock file, but in this case you can't write one, ....).

Perhaps when you ask for exclusive+read only and you don't have permission for the folder, you don't really get a real 'exclusive' mode (and others can come along and possibly modify it while you're using it). I imagine this could cause errors for the read-only user (which might happen anyway in proper shared mode).

I assume you'll want to just give write permission for the folder?

Regards,
Andrew.
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question