Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Subform Record Limit
Chris Lopez 
      
5 months ago
Hi,
I have a continuous subform in the main form, is there a way to limit the number of records that can be entered in the subfrom, so that there is no scrolling, once the viewable records are full, no more can be added, 1 sub form will allows 30 records before it has to start scrolling, so id like to stop at 30. This way, when I print a report, it will only print the 30 records.

Thanks
Donald Blackwell  @Reply  
       
5 months ago
In VBA, you could do a recordcount in the AfterUpdate of the form to see how many records are attached to that parent record and if 30, then change the form property "AllowAdditions" to false.

On the other hand, you could use a query to filter the # of records a report shows to 30 as well so the subform could take all relevant records that go to the master form and then only print 30 in the report before having to go to a new page/report.
Donald Blackwell  @Reply  
       
5 months ago
Correction, to do in the form, would be in the After Insert event.

And, if that were the route you choose to take, you'd also need to check the record count every time the form opens and every time the parent form moves to a new record.
Chris Lopez OP  @Reply  
      
5 months ago
I dont want it to go to a new report. I want it stop at 30, and no more. How do I do the after insert event with VBA?
Donald Blackwell  @Reply  
       
5 months ago
In that event directly would be something like:

DetailsPrivate Sub Form_AfterInsert()

    If Me.Recordset.RecordCount > 29 Then
        Me.AllowAdditions = False
    End If
    
End Sub


That would lock the form so no more records could be added. But again, you'd need to check when the parent form loads or changes records to determine whether the subform should be able to accept new records. So, I would turn that code into a separate public function that could be called from anywhere:

Public Function LockIfFull()

    If Me.Recordset.RecordCount > 29 Then
        Me.AllowAdditions = False
    else
        Me.AllowAdditions = true
    End If
    
End Sub

Then in the property sheet of the subform, I would just call that function anywhere the number of records needs checked by typing: =LockIfFull() into each property in the sub form's events tab - see image below:
Donald Blackwell  @Reply  
       
5 months ago

Donald Blackwell  @Reply  
       
5 months ago
If you allow users to delete records in the sub form, I would disable deletions in the form itself and put a button somewhere so you can control it with code. For example:

DetailsPrivate Sub DeleteBtn_Click()

     ' Make sure they actually want to delete the record
     If MsgBox ("Are you sure you want to delete the selected record?", _
          vbYesNo + vbQuestion, "Confirm Deletion" ) = vbYes Then

          ' If Action/Delete Warnings are enabled in the database, turn them off since we know it will fire
          DoCmd.SetWarnings = False
          
          ' Use SQL to delete the selected record
          CurrentDb.Execute("DELETE FROM tablename WHERE recordid=" & recordid)

          ' Requery the table to get an updated record count and call the function to enable or disable additions
          Me.Requery
          LockIfFull

          ' Turn Warnings back on to be safe
          DoCmd.SetWarnings = True
     End If

Exit Sub


* Replace "tablename" and "recordid" as approriate

This would ensure that when the main form loads, it loads this form and it checks if it's full. each time you go to a new record in this form, it verifies if it's full. If you delete a record, it verifies if it's full. If the main form moves to a new record, then this will start over and verify if it's full. This way, if multiple people are working in the same form ever, it will frequently verify when it gets full.
Chris Lopez OP  @Reply  
      
5 months ago
The AfterInsert event would go in the subform that I want to control?
Donald Blackwell  @Reply  
       
5 months ago
Yes, that would stop them from entering any more rows at that time.
Chris Lopez OP  @Reply  
      
5 months ago
Donald How do I get the Public Function in? I can't remember. Is it a separate VBA module?
Donald Blackwell  @Reply  
       
5 months ago
As long as you're only calling it from within that sub form, you can put it in that forms code. If you call it from the form's property sheet like the image I showed, you could just replace the Private Sub Form_AfterInsert() with the Public Function...

Oooh, I just noticed a typo in what I had above for the Public Function, the last line should be "End Function" and not "End Sub"
Chris Lopez OP  @Reply  
      
4 months ago
I got it to work as I needed it to.

Thank you

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/6/2026 4:32:19 AM. PLT: 0s