> I don't think i phrased the question very well.
I have a Client table with a field called "Supervisor" where i enter
a supvisor number.
I then have a Supervisor table where there is a field called "Number
to clients that can be monitored"
Every time a new client is entered into the table and a supervisor is
assigned, i need to decrement the value in the supervisor table.
No you don't. You just put a maximum value of clients that this
supervisor *can* monitor in the supervisor table. then if you do a
DCOUNT() on the Clients table with that supervisor's ID as the
argument, you'll get the number of clients that supervisor is *already*
supervising. And then that's where the BeforeInsert comes in. Okay,
so you don't have a Main/Sub going on. You can do it all from the
Clients form. Here's the code I used to do it....
Private Sub SuperID_BeforeUpdate(Cancel As Integer)
If DCount("[SuperID]", "tblClient", "[SuperID] =" & Me.SuperID) =
DLookup("[MaxClients]", "tblSupervisor", "[SuperID] =" & Me.SuperID)
Then
MsgBox "This supervisor is already at max." & vbCrLf & "Please
assign to another supervisor."
Cancel = True
End If
End Sub
the DCOUNT gets the number of clients the given supervisor is already
supervising.
the DLOOKUP get the MAX number of clients the given supervisor can
supervise.
If the two numbers are already equal, the Supervisor is already working
at capacity and cannot have any more cases added. So I reject the
update to the chosen value (the supervisor(ID)) and prompt the user to
assign another supervisor. No need for a main/subform.
For the report, you can either do a summary for each supervisor and
show just the counts (MaxCaseload vs. CurrentCaseload) where
CurrentCaseload would just be the number of child records (Cases) the
supervisor has. Remaining slots or whatever is just Max-Current.