Solved

Count of records in Subform

Posted on 2015-01-31
3
351 Views
Last Modified: 2015-02-01
Update Count of records in Subform when a record is deleted.

I have a main form with a continuous subform. I want a number of records in the subform value in a text box on the main form.  I have tried  an unbound control that gets it's value from a DLookUp but I cannot get it to update when a record is deleted from the subform. There must be a simple solution to this.
0
Comment
Question by:DatabaseDek
3 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40582094
try using the afterDelConfirm event of the subform
0
 
LVL 29

Accepted Solution

by:
IrogSinta earned 500 total points
ID: 40582130
One way is to put a hidden unbound textbox in the subform's header or footer with the following expression:
=Count([aFieldInYourRecordsource])
Then in the unbound textbox in the main form, use something like this:
=[nameOfSubformControl].Form.[nameOfHiddenTextbox]

The disadvantage with the above approach is there seems to be a delay in getting textbox to recalculate.  If you need a more immediate response, you can use the AfterDelConfirm event as mentioned by Rey with the following code:
Parent.nameOfTextboxOnMainForm = Me.RecordsetClone.RecordCount

If you're inserting records and you want the count updated, you need to add the same code to the AfterInsert event.  Also, if you want to see the count when you first open the form, you should do the same on the subform's OnOpen event.

You can do something like this:
Private Sub Form_AfterDelConfirm(Status As Integer)
    Call RefreshCount
End Sub

Private Sub Form_AfterInsert()
    Call RefreshCount
End Sub

Private Sub Form_Open(Cancel As Integer)
    Call RefreshCount
End Sub

Private Sub RefreshCount()
    Parent.txtCount = Me.RecordsetClone.RecordCount
End Sub

Open in new window

Ron
0
 

Author Closing Comment

by:DatabaseDek
ID: 40582289
You wouldn't think that something that simple could require such work.

Brilliant!

Thank you.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now