Opendatabase (need shared access to MDB) Word 2000

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15642
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Opendatabase (need shared access to MDB) Word 2000

Post by ChrisGreaves »

Code: Select all

Public Function dbOpenMDBDatabase(strFileName As String) As Database
    Dim strPath As String
    strPath = strFileName
    Set dbOpenMDBDatabase = OpenDatabase(strPath, True, False)
End Function
My code works well from my Word2000 application that harvests strings. I select strings from a document, paste them into an RST record, and then run a macro which opens the database (VBA code above - I know that strPath is redundant) and adds the record.
I am happy.

However, if the Access database is already open (by me checking to see if a record already exists), the VBA open fails because someone else (me) has the database open.
I cannot find "OpenDatabase" in the Word VBA help, not surprising. In Access VBA I can find the keyword, but no help screen comes up.

I have a feeling that one of the "Options" in the OpenDatabase method might allow multiple access, but cannot find out how.

For what it's worth right now I'd be happy if me-as-end-user had read-only access to the database as long as the VBA code can add records on command.
He who plants a seed, plants life.

User avatar
HansV
Administrator
Posts: 78582
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Opendatabase (need shared access to MDB) Word 2000

Post by HansV »

The syntax for OpenDatabase is

OpenDatabase(Name, Options, ReadOnly, Connect)

Name (required) is the full path and filename of the database.
Options (optional) is True to open the database in exclusive mode, False to open it in shared mode.
ReadOnly (optional) is True to open the database in read-only mode, False to open it in read/write mode.
Connect (optional) can be used to specify various information, such as a database password.

So I think you want OpenDatabase(strPath, False, False) or perhaps OpenDatabase(strPath, False, True)
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15642
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Opendatabase (need shared access to MDB) Word 2000

Post by ChrisGreaves »

HansV wrote:So I think you want OpenDatabase(strPath, False, False) ...
:fanfare:

Thanks Hans.
I know I used to have something like this working a few years back. can't remember what applicaiton.
I have to get my help files working again.
Might you please tell me which Help files you grabbed the quote from?
Access VBA?
Thanks
He who plants a seed, plants life.

User avatar
HansV
Administrator
Posts: 78582
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Opendatabase (need shared access to MDB) Word 2000

Post by HansV »

Yes, it's part of the DAO help. The online version for Access 2007 is OpenDatabase Method [Access 2007 Developer Reference] but it's 99% 9or more the same as for Access 2000.
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15642
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Opendatabase (need shared access to MDB) Word 2000

Post by ChrisGreaves »

HansV wrote:Yes, it's part of the DAO help.
Thanks for the landmarks, Hans.

OK, I have found a file DAO360.CHM on my office2000 CD, but it does not appear to have been installed on the machine - even 'though I habitually click "I've got a large hard disk, install everything".
I have found what I needed:

Code: Select all

Setting Description 
True Opens the database in exclusive mode. 
False (Default) Opens the database in shared mode.
I got this clue after a Google Search turned up this page
Perhaps a re-installation of Office 2000 is called for.

I expected that, within Word2000/VBA, with a reference to the DAO 3.6 Object Library (hence my ability to make use of the OpenDatabase method) tapping the F1 function key while on the OpenDatabase keyword should have brought up this page from the DAO360.chm file, is that correct?

If so then it confirms my belief that my Office2000 installation is wonky.
He who plants a seed, plants life.

User avatar
HansV
Administrator
Posts: 78582
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Opendatabase (need shared access to MDB) Word 2000

Post by HansV »

When Microsoft released Office 2000, they wanted to phase out DAO in favor of ADO, and they made it difficult to get info about DAO. Most developers didn't appreciate this. With Access 2002 (aka XP), Microsoft had already seen the error of their ways, and made DAO more available again (although ADO remained the default); in Access 2003 DAO once again became the default...
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15642
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Opendatabase (need shared access to MDB) Word 2000

Post by ChrisGreaves »

HansV wrote:... in Access 2003 DAO once again became the default...
Thanks.
No wonder I feel jerked about!
He who plants a seed, plants life.