Answers inline:
tboggs said:
Your code has definitely got me going in the right direction, but I’m
getting
some errors. I believe this is becoming more difficult because the first
guy
that made the database put spaces in the names of objects as you will see
below.
My fault for not being clear enough. I meant a field of type text with a
length of 50. There ought to be 1 field called FormLock. It's type should be
set to Text. If your table is open in design view and you select the field's
name in the top list, the bottom part of the screen shows a property called
Field Size. Set this to 50. Also I think you may have trouble with your
table having the same name as your field. Rename the table to (say)
FormLocks.
The purpose of this table is to contain the name of any open form which you
need to lock, so when the form opens it adds a record with FormLock
containing it's own name. This indicates that the form is 'busy'. When the
form is closed, the same record is deleted, thereby 'freeing up' the form
for use by others.
Then, I created a field in the normal table (Case Files) that records are
saved to in the form I want to lock (Add New Case File). The field is
also
called FormLock Text 50
I don't see a need for this and definitely didn't suggest it.
Finally, I added that field to the form (Add New Case File) and made the
FormLock fields correspond to each other between the two tables (1 record
to
1 record). I also made this text box invisible on the form.
Again, no need to do this (that I can see).
---------------------------------------------------------------------
Here is the code that I’m currently using on the OnOpen Event:
If DCount("'Add New Case File'", "Case Files", Me.FormLock) > 0 Then
MsgBox ("You may not open this form until another user exits.")
DoCmd.Close
Exit Sub
End If
CurrentDb.Execute "Insert Into Case Files Set Add New Case File = '" &
Me.FormLock & "'", dbFailOnError
Totally wrong I'm afraid. It needs to be something like:
If Dcount("FormLock", "FormLocks", "FormLock = '" & Me.Name & "'") Then
MsgBox ("You may not open this form until another user exits.")
DoCmd.Close
Exit Sub
End If
CurrentDb.Execute "Insert Into FormLocks Set FormLock = '" & Me.Name & "'",
dbFailOnError
I don’t get any errors, but the form seems to think that someone is
already
in it and will not let the first user in.
------------------------------------------------------------------
Here is the code that I’m currently using on the OnClose Event:
CurrentDb.Execute "Delete From Case Files Where Add New Case File = '" &
Me.FormLock & "'", dbFailOnError
Wrong again:
CurrentDb.Execute "Delete From FormLocks Where FormLock = '" & Me.Name &
"'", dbFailOnError
On this event, I get run-time error 3075: syntax error (missing operator)
in query expression ‘Add New Case File =’”.
I’ve tried putting underscores between Case Files and Add New Case File,
but
this also gives me the error:
Run-time error 3078
The Microsoft office access database engine cannot find the input table or
query ‘Case_Files’. Make sure it exists and that its name is spelled
correctly.
Try doing it the way I described above.
<SNIP>