Similar to "Limit Record Creation"

J

jb

I have a situation similar to the above post of 7/25/08. My form is a main
form with a subform, and a subform inside of that. My problem is with the
sub-subform.

The database is about scholarships awarded to students. The main form is
the student information; the first subform is the scholarship awarded and how
many years it is for; the sub-subform contains the records of actual payouts
(1 record for each of the years shown in the subform).

I would like the sub-subform to stop allowing new records when the max years
has been reached. In this sub-subform I created a control in the footer that
calculates how many payout records exist for this scholarship so far. I
would like it to compare that control with the field on the subform that
indicates the years allowable. When it has reached that number, the
AllowAdditions needs to change to false. I've tried a number of things and
can't seem to get it to work. Any suggestions would be so much appreciated.
Thank you.
 
D

Danny J. Lesandrini

I suppose the best place to interrupt the addition of a new record would
be the Before_Insert

Private Sub Form_BeforeInsert(Cancel As Integer)
If LimitIsReached() Then
Cancel = True
MsgBox "Can't add another. Sorry."
End If
End Sub

The function referenced above, LimitIsReached(), is where you put the
logic to determine if the new record should be allowed.

However, there's another approach. Why not build the full compliment of
year records first, lock the year field so they can only edit other data, and
turn off the AddNew and Delete methods of the form.
 
J

jb

Thank you! By putting the coding as you described, it works! I had hoped to
have the new record line be unavailable, but this is just as good. Thank you
for your wisdom!
 

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