Code to make table exclusive

  • Thread starter Thread starter Paul3rd
  • Start date Start date
P

Paul3rd

Hello, I have in my split database a form that relies on one table (ApptDis).
When a user on the network has that form open, I'd like to inform/block any
other user from opening the form by denying the table read property.
I've started working on the code to go in the OnOpen event of the form, and
so far I have:

Dim rst As Recordset
Dim Answer As Integer

Answer = MsgBox("Form in use by another user...Please Wait", vbOKOnly)
Set rst = CurrentDb.OpenRecordset("ApptDis", dbOpenTable, dbDenyRead)
If Err.Number <> 0 Then
MsgBox ("Err Number = 0")
If Answer = vbOK Then
Exit Function
End If
End If
rst.Close
But it does not work, I get an error message saying that the table has a
process running and cannot be locked. I don't know what that process might be.
Am I on the right path? or am I going in the wrong direction entirely?
Any help would be greatly appreciated.
Paul
 
Paul,

I think, if I wanted to prevent more than one person having access to a form
at a time (I cannot really think of a reason to do this). I would add a field
(Yes/No) to my db_Parameters table. Then in the forms Open event, I would
check to see whether this value was true. If so, I would cancel the load.
If false, I would set it to True, then continue opening the form. Then, in
the forms close event, I would set it to false.

HTH
Dale
 
Thanks Dale,
My form has an imbedded worksheet as an OLE object. The form opens onto the
current date and I wanted to eliminate the possibility of two (or more)
people trying to edit the worksheet simultaneously.
I'll work on it some more,
Thanks again for the advice.
Paul
 
Back
Top