Limit Data Entry To Three Records

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
 
P

Pavel Romashkin

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
 
N

Nancy

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
 
T

TC

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

TC
 
P

Pavel Romashkin

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
 

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