If you use the command line function, you'll need to verify the correct path on each user machine. Personalization is the only way around the problem. You could use a setup program to create the shortcuts on each machine.
I've devised a way to open the database exclusively using code but I'm not sure it will work if your site uses various versions of Access. I'll post the code here and you can use it if you want.
The code works in Access 2000. If you use an earlier version, you will need to modify the code.
Basically, the functions determine if the database is open in EXCLUSIVE mode. If not, the code determines the path to the Access program and starts Access, opening the database in exclusive mode.
Create the following functions in a VBA module. Add a call to the function
OpenDatabaseExclusive() in your startup form On Load event or in a macro (AutoExec?) that executes upon opening the database. Let me know how it works if you use it.
Function IsCurDBExclusive() As Integer
'This function comes from Microsoft at 'The access 97 version is at 'It requires the Microsoft DAO 3.6 Object Library. From VB, check references and make sure the DAO 3.6 reference is checked ON.
'Purpose: Determine if the current database is open exclusively.
'Returns: 0 if database is not open exclusively.
' -1 if database is open exclusively.
' Err if any error condition is detected.
Dim db As DAO.Database
Dim hFile As Integer
hFile = FreeFile
Set db = CurrentDb
If Dir$(db.Name) <> "" Then
On Error Resume Next
Open db.Name For Binary Access Read Write Shared As hFile
Select Case Err
Case 0
IsCurDBExclusive = False
Case 70
IsCurDBExclusive = True
Case Else
IsCurDBExclusive = Err
End Select
Close hFile
On Error GoTo 0
Else
MsgBox "Couldn't find " & db.Name & "."
End If
End Function
Function OpenDatabaseExclusive()
Dim AccPath As String, rc As Double, dbPath As String
Dim db As DAO.Database
If IsCurDBExclusive() = False Then
Set db = CurrentDb
dbPath = db.Name
db.Close
AccPath = SysCmd(acSysCmdAccessDir) & "msaccess.exe "
rc = Shell(AccPath & dbPath & " /excl", vbNormalFocus)
Quit
End If
End Function
------------------------------------------
Another option would be to have every user open another database (StartUp.mdb?) with only one function in it - no tables, forms, etc. Include an AutoExec macro to execute the function. The function would be similar to the OpenDatabaseExclusive above. The test for exclusive use is removed.
When users open the StartUp.MDB, the code would run, determine the correct paths and start Access to open the production datbase exclusively.
Function OpenDatabaseExclusive()
Dim AccPath As String, rc As Double, dbPath As String
Dim db As DAO.Database
Set db = CurrentDb
dbPath = db.Name
db.Close
AccPath = SysCmd(acSysCmdAccessDir) & "msaccess.exe "
rc = Shell(AccPath & dbPath & " /excl", vbNormalFocus)
Quit
End Function Terry Broadbent
Please review faq183-874.
"The greatest obstacle to discovery is not ignorance -- it is the illusion of knowledge." - Daniel J Boorstin