Gustav Brock
gustav at cactus.dk
Fri Jan 23 07:13:39 CST 2004
Hi John > I need to set up a subform that only allows a single record to be entered. > I have a function in the subform that checks if the > recordsetclone.recordcount >0 and if so sets AllowAdditions = false. This > works fine if any records already exist but if a new record is created, then > if the person does a page down to save the first record, they end up in a > second record. I am firing this function I built from the OnCurrent of the > parent, as well as the OnCurrent of the subform itself. Haven't tried yet > from before update. > Does anyone do this kind of thing? If so how do you accomplish it? If you can't or won't control this is at the table level, we have this generic function: <code> Public Sub SetFormAllowAdditions( _ ByVal frm As Form, _ ByVal lngRecordCountMax As Long) ' Limits count of records in subform. ' ' Usage: ' Add this line for max. n rows: ' ' Call SetFormAllowAdditions(Me.Form, n) ' ' in these subs of the form: ' ' Form_AfterInsert() ' Form_AfterDelConfirm(Status As Integer) ' ' And in the main form: ' ' Call SetFormAllowAdditions(Me!subFrmControl.Form, n) ' ' in this sub of the main form: ' ' Form_Current() ' ' 2003-01-28. Cactus Data ApS. CPH. Dim booAllowAdditions As Boolean With frm booAllowAdditions = (.RecordsetClone.RecordCount < lngRecordCountMax) ' Only change edit state if needed. If booAllowAdditions <> .AllowAdditions Then .AllowAdditions = booAllowAdditions End If End With End Sub </code> /gustav