Limiting Records from Query

R

Ripper

I have a table used to sign up students for a class. The maximum per class
is 20 in each class and I use a unique class ID for each course. How do I
have the number of people who sign up stop when the class is full?

I use a query to count the CourseID. If the participation max is reached,
is there a way to display an message box that says, "You're too late. Class
is Full."
 
J

John Vinson

I have a table used to sign up students for a class. The maximum per class
is 20 in each class and I use a unique class ID for each course. How do I
have the number of people who sign up stop when the class is full?

I use a query to count the CourseID. If the participation max is reached,
is there a way to display an message box that says, "You're too late. Class
is Full."

If (as you should be!) you're using a Form to enter the data -
presumably a Subform on a Classes form - you can use code in the
form's BeforeInsert event, using DCount() to count the current
signups. If there are already 20, post a message and cancel:

Private Sub Form_BeforeInsert(Cancel as Integer)
If DCount("*", "[Reg]", "[ClassID] = " & Me.ClassID) >= 20 Then
MsgBox "Class full! Sorry!", vbOKOnly
Cancel = True
End If
End Sub

John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top