Limitations to data entry into a subform

B

Bill

Within a subform, can data lines be limited to say 38 line
entries? At which time a warning message will appear at
the 39 line entry, "Data is limited to 38 line entries"?
 
N

Niklas Östergren

Yes it is!

This is the way i did it in a while ago:

==================================================
Dim recClone As Recordset
Dim YourValueOfMaxNumberOfRecordsGoesHere As Integer

' Clone the set of record from form.
Set recClone = Me.RecordsetClone()


' Move to the last record in the recordset.
recClone.MoveLast


' If more then YourValueOfMaxNumberOfRecordsGoesHere records present msg and
set 'Me.AloweAdditions = False

If recClone.RecordCount > (YourValueOfMaxNumberOfRecordsGoesHere- 1)
Then
recClone.MovePrevious
MsgBox "Max " & YourValueOfMaxNumberOfRecordsGoesHere& "
Your warningsmessage", vbOKOnly + vbInformation, "Max number of records"
DoCmd.CancelEvent
Me.AllowAdditions = False
Exit Sub
Else
Me.AllowAdditions = True
End If

' Close the recordset.
recClone.Close
==========================================================

I hope this can help you out!

// Niklas
 
V

Van T. Dinh

I am not sure whether you meant 38 Child Records / Rows that are related to
the Parent Record in the Main Form or 38 lines in a TextBox, possibly bound
to a Memo Field?

If you meant 38 Child Records, my guess is that you can use the (Subform)
Form_AfterInsert Event to count the number of Records in the Subform and if
it is => 38, set the AllowAdditions Property of the Subform to False.

Note that you will have to write similar code in the Form_AfterDelConfirm to
check whether the RecordCount is < 38 (after deletion) and if it is, reset
the AllowAdditions back to True.
 

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