limit records in a subform

HarrySpencer

Registered User.
Local time
Today, 03:47
Joined
Apr 10, 2007
Messages
25
Hello, I've not been able to locate any information on this and I'm guessing I'll need to do this with some VBA code.

I have a table called person with associated fields, name, dob, address, etc and a table called timetable that holds day, start time, end time.

I've setup the timetable as a sub-form of the person form, what I would like to do is limit the number of records that the timetable table/form can hold a maximum of 7 records (each day of the week) and validate so only one of each day can be used.

I was think I could try and match the newest added timetable record against others for that person and see if any days match but can't think of the code. From waht I've read so far would recordset or clone functions work?

many thanks, Harry

p.s. I've just switch to using Access 2007
 
You an use the BeforeInsert event to count the number of records. When it exceeds 7, cancel the event.

Enjoy!
 
EXCELLENT!!! That works perfectly. Cheers

Here is the code I've used if anyone is interested.

Private Sub Form_BeforeInsert(Cancel As Integer)
If Form.RecordsetClone.RecordCount > 6 Then
Cancel = True
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom