Limit Data Entry To Three Records

  • Thread starter Thread starter Nancy
  • Start date Start date
N

Nancy

I have two tables:

TblCourse
CourseID
CourseName

TblClass
ClassID
CourseID
ClassDate

Classes are entered in a subform. How do I limit data entry to a max of 3
classes for any course?

Thanks!

Nancy
 
Try putting this code in the subform's Current event:

if Me.NewRecord then
if Me.RecordsetClone.RecordCount > 2 then
MsgBox "Only three entries allowed."
Me.Recordset.MoveFirst
endif
endif

Pavel
 
Pavel,

Thanks for responding!

Your code limits data entry to 3 total records. That's not what I want. I need
to limit data entry to 3 classes for any course. Total records could be well
over 100.

Nancy
 
He presumeably assumed that the subform was displaying the classes for the
course selected in the main form.

TC
 
TC is correct. The code I suggested is to be put into the subform module
where you are entering the classes for a given course, where the course
is chosen on the main form and the subform lists the classes for the
given course.
If you have a different design, you may want to use a query to find the
amount of records:

SELECT Count(ClassID) FROM TblClass WHERE CourseID = MyCourseID AND
ClassID = MyClassID

and then use it in any way you want.
Pavel
 
Back
Top