Count Records in a Continuous Form (1 Viewer)

Weekleyba

Registered User.
Local time
Today, 11:41
Joined
Oct 10, 2013
Messages
586
I have a continuous subform that I want to display the record count in a text box outside the continuous form.
See below "Projects found". Note in the footer I made visible the text box "Count"

1665408615330.png


In "Count" is =Count(*) text box name is txtCount.
In "Projects found" is =[F_ProjectContract].[Form]![txtCount]

This works until I have no records then give me an #Error.
How do I fix this?

1665408863849.png
 

Minty

AWF VIP
Local time
Today, 17:41
Joined
Jul 26, 2013
Messages
10,371
Try putting an NZ() in txtCount

=Nz(Count (*) , 0 )
 

Weekleyba

Registered User.
Local time
Today, 11:41
Joined
Oct 10, 2013
Messages
586
It gives the exact same error.
1665410570263.png


And does not give the 0 in the Count text box. ?
1665410646750.png
 

Minty

AWF VIP
Local time
Today, 17:41
Joined
Jul 26, 2013
Messages
10,371
Sorry I hadn't realised the subform was empty.

Do you have a saved query for your sub form row source?
If you do you can use a dcount() directly on that query using the same criteria as your subform link/search criteria.
 

Weekleyba

Registered User.
Local time
Today, 11:41
Joined
Oct 10, 2013
Messages
586
Well...that's a bit tricky for me. I have a dynamic search that requeries the subform.
I think I'll just leave the Count in the footer as that at least does not show the error.
May I'll work in this another time.

1665413216225.png


I did try this but didn't work.
1665413307121.png
 

CJ_London

Super Moderator
Staff member
Local time
Today, 17:41
Joined
Feb 19, 2013
Messages
16,637
you can use a listbox - use a rowsource something like

SELECT Count(*) FROM (subformrecordsource)

subsitute subformrecordsource with whatever your dynamic sql is

set the list rows to 1, suggest also disable and lock

you'll need to replace it each time

lstProjects.rowsource="SELECT Count(*) FROM (" & dynamic sql & ")"
which you can do at the same time you assign your dynamic sql to the subform recordsource

gets a bit more complicated if users can filter the subform but can be done

probably want to set the rowsource to "" on first open to not display anything or to something like "SELECT TOP 1 0 FROM msysObjects" to display a zero
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:41
Joined
Feb 19, 2002
Messages
43,372
Assuming the white areas are the footer of the subform, use the following as the ControlSource of a control in the subform's footer section:

=Count(*)
 

CJ_London

Super Moderator
Staff member
Local time
Today, 17:41
Joined
Feb 19, 2013
Messages
16,637
@Pat Hartman - that was the original problem per post #1 - you get an error if there are no records
 

LarryE

Active member
Local time
Today, 09:41
Joined
Aug 18, 2021
Messages
593
I have a continuous subform that I want to display the record count in a text box outside the continuous form.
See below "Projects found". Note in the footer I made visible the text box "Count"

View attachment 103774

In "Count" is =Count(*) text box name is txtCount.
In "Projects found" is =[F_ProjectContract].[Form]![txtCount]

This works until I have no records then give me an #Error.
How do I fix this?

View attachment 103775
Try In "Projects found"
=Nz(Forms![F_ProjectContract]![txtCount],0)
 

Users who are viewing this thread

Top Bottom