View Full Version : dynamically limit records in subform


kgcrowther
07-19-2001, 01:25 PM
I have a form with a sub form. The subform is in the default view "continuous forms" so that multiple items can be viewed at a time. I want to be able to specify how many items may be entered based on a number in the main form.

More specifically, we want to track our software. We want to keep track of software and hardware keys that are issued to employees so that we don't break any license laws. We own a different number of licenses for each type of software. I've set up the form so that main software information is in the main form and employee information is in the subform in continuous view so that you can see all the employees who have a key. (there is usually three to ten)

Does anyone have any ideas how to either limit the number of employee entrees, or at least give a warning message everytime too many are entered?

Any ideas will be helpful. Thanks.

Kenneth

Pat Hartman
07-19-2001, 04:10 PM
In the BeforeInsert event of the subform, use a DCount() function to count the number of previously issued licenses. If the count is >= to the max field on the main form, cancel the insert and display a message.

Jack Cowley
07-19-2001, 04:23 PM
You could use DCount in the On Current event of the form that is your subform to do a count of the records. If the count is equal to or exceeds the acceptable number you can pop up a message and then send the user back to the previous record thereby not allowing he/she to continue.

PS. Pat's idea of before insert is superior.



[This message has been edited by Jack Cowley (edited 07-19-2001).]

kgcrowther
07-23-2001, 09:08 AM
This works great. I'm wondering why it needs to be >=. I tried just putting > and it didn't work right. I would think in my mind that when they are equal I should still be able to enter (and I can still enter with the >= command) Does it start counting with 0 or something.

Well I guess it's not that important, because it does work. Thankyou very much,

Kenneth

Pat Hartman
07-23-2001, 10:03 AM
It needs to be ">" because you don't know if there's any bad data already in the table and it needs to be "=" because you are comparing the number of rows already in the table to the Max allowed, not the number there plus the one you are adding. So if the Max is 5 and 5 already exist, you don't want to add the 6th. The test is in the BEFORE insert event so you can cancel the update if it fails. If you put the test in the AFTER insert event, ">" would work just fine. Unfortunately, you would already have added the bad data to the table. Then you would have to delete it.