subform record count (1 Viewer)

gisler87

New member
Local time
Today, 01:14
Joined
Mar 12, 2009
Messages
6
hello,

i have been working on trying to get a atribute in the main form to count the ammount of records in the subform.

tried this code but just get #name?

=form!mainform!subform.form.recordset.recordcount

any input would be apreciated

many thanks

andrew
 

gisler87

New member
Local time
Today, 01:14
Joined
Mar 12, 2009
Messages
6
Hi,

I am using the correct container name. I did try using there cod:


Forms("frmTest").Controls("MyContainerName").Form.recordsetclone.recordcount

instead of getting #name? With the above code i get #error. Is it possible i am getting #error because i am running in sandbox mode?

Edit: The name of my form is Add CD and the name of my subform is called Add CD subform. The main form has all the Catalogue ID's and the subform lists all the CD's for that Catalogue. I want to be able to count the amount of cd's for the catalogue.

Many thanks

Gisler87
 
Last edited:

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 08:14
Joined
Sep 12, 2006
Messages
15,614
one way

in the footer on the subform put a textbox itemcount with control source = count([somefield])

now in the mainform put a reference another text box, with the control source

=subdetails!itemcount

-------------
what you are trying to do, is count the items in the subforms recordsource, i think

which you can do with dcount("*",subdetails.recordsource) (this syntax might be off - you may need to show the name of the query directly) but this may not yield the xorrect results, if the users filter the subform directly, rather than via the query
 

ansentry

Access amateur
Local time
Today, 19:14
Joined
Jun 1, 2003
Messages
995
Put and unbound text box on the main form and put below as the data source and it will work.


=SubformName.Form.RecordsetClone.RecordCount


If this does not work then most likely you have changed the subfrom name and not changed the name of the control (subform) on the main form.

Hope it works for you.
 

boblarson

Smeghead
Local time
Today, 01:14
Joined
Jan 12, 2001
Messages
32,059
Using the actual names of your forms (and IF the subform CONTAINER - container on the subform that houses the subform on the main form is named the same as the subform) it should work with:



=[Add CD subform].Form.RecordsetClone.RecordCount

But since you have the spaces in the name you need the square brackets.

For control sources, this actually makes it easier to get the syntax in:
http://www.btabdevelopment.com/main...bformsincontrolsources/tabid/106/Default.aspx
in place of the other link I gave you earlier. The other link is more for VBA Code and not for control sources.
 

Cl0n3Tr00per

New member
Local time
Today, 05:14
Joined
Mar 18, 2009
Messages
4
Question: Is the subform bound to a table Query?

If so, I've got away with a simpler query a bunch of times: Dcount("field to count", "table", "(criteria, ie: "1ry key field = " & variable)"

Set the variable to the value of some textbox bound to a field whose value is shared across the current subform record, and that's it! If there isn't such a textbox, use your 1ry subtable key field.

Problem Solved.

This query seems to be much more efficient than dealing with recordsets.
 

boblarson

Smeghead
Local time
Today, 01:14
Joined
Jan 12, 2001
Messages
32,059
This query seems to be much more efficient than dealing with recordsets.
Actually, not true as the recordset in question is already open and the data is there. Using a domain aggregate, especially if in a database with a LARGE number of records, would potentially be very, very slow comparatively speaking.
 

Cl0n3Tr00per

New member
Local time
Today, 05:14
Joined
Mar 18, 2009
Messages
4
Actually, not true as the recordset in question is already open and the data is there....

-I thought that the whole purpose of the dcount function was to speed things up, especially when dealing with a large number of records and a single result is required.

-Forgive my noobness (I stopped being a decent code monkey when DAO stopped being fashionable ); but don't you need to declare, open, load and finally close a separate recordset in order to perform the requested operation? For real, I'd like to know.

Cl0n3
 

boblarson

Smeghead
Local time
Today, 01:14
Joined
Jan 12, 2001
Messages
32,059
-I thought that the whole purpose of the dcount function was to speed things up, especially when dealing with a large number of records and a single result is required.

-Forgive my noobness (I stopped being a decent code monkey when DAO stopped being fashionable ); but don't you need to declare, open, load and finally close a separate recordset in order to perform the requested operation? For real, I'd like to know.

Cl0n3
Actually, in this case we were using the form's RecordsetClone which is already open and populated. So, it is quicker than doing anything else - just go get it.
 

gisler87

New member
Local time
Today, 01:14
Joined
Mar 12, 2009
Messages
6
thanks for all your help. got it working now.

Many thanks
 

Users who are viewing this thread

Top Bottom