andrew v via AccessMonster.com said:
there are two sessions per day, morning and afternoon Mon thru Fri.
the subform will only reflect information regarding a customer with
the following fields that the user can enter...
Event, EventDate(setup as current date), EventTime, ScheduledBy
ie. Testing, 3/28/05, AM, John Doe
the dcount function is taking this information and calculating how
many customers have been reserved for either the morning or afternoon
session from tblEvents. i have a total of 10 unbound text boxes to
reflect the five days and sessions. there are only 16 available
seats per session.
right now it will go over the 16 limit. i need help on putting a max
limit of 16 with the dcount unbound text box so that when a user is
trying to add another customer to the session they will be unable to
do so. sorry for the confusion.
This is still a little unclear to me, so let me talk through my
understanding. The purpose of the form and subform is to book a
customer for various sessions, where a session is defined by the
combination of the fields Event, EventDate, and EventTime. The form is
customer-centric, so you are working with a particular customer,
choosing various sessions for that customer. The subform enters the
Customer, Event, EventDate, and EventTime into a table to do the
booking. You are trying to enforce a constraint that no session can
have more than 16 customers booked into it.
Your questions up to this point imply that tblEvents is the table that
is storing all the booking information. That doesn't actually sound
like a proper design to me, as I'd expect you to have at least these
tables:
Events (one record per event)
Sessions (one record per Event+EventDate+EventTime)
Customers (one record per customer)
SessionsCustomers (or "Bookings" -- one record per
Customer+Session )
I'm not going to pursue this further for the moment, but rather go on
with what appears to be your current table design.
The simplest way to enforce your constraint would be to put code into
the subform's BeforeUpdate event that checks for overbooking. For
example:
'----- start of example code -----
Private Sub Form_BeforeUpdate(Cancel As Integer)
If DCount("*", "tblEvents", _
"EventID=" & Me!EventID & " AND " _
"EventDate=#" & Format(Me!EventDate, "mm/dd/yyyy") & _
"# AND " & _
"EventTime='" & Me!EventTime & "'") _
Then
MsgBox "Sorry, that session is fully booked."
Cancel = True
End If
End Sub
'----- end of example code -----
A somewhat better way might be to either set up the form so that booked
sessions can't be chosen, or set it so that booked sessions are
automatically flagged as closed. However, advice along those lines
would require me to know more about your table and form design than I
do.