[AccessD] subform only allows one record

Colby, John JColby at dispec.com
Fri Jan 23 09:05:11 CST 2004


Gustav,

Thanks for that.  Controlling this at the table level means that the user is
notified either when she attempts to create a new record or when she tries
to save a new record.  Either way is klunky.  I don't want my users even
seeing the new record if they already have one record or if they have just
finished saving the first record.  It is that "just finished saving" that is
throwing me off.  It's almost as if in order to leave this record (and thus
save it) you must go to a new record which I don't want happening.

John W. Colby
The database guy


-----Original Message-----
From: Gustav Brock [mailto:gustav at cactus.dk]
Sent: Friday, January 23, 2004 8:14 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] subform only allows one record


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

_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com


More information about the AccessD mailing list