Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count records loaded by subform

Status
Not open for further replies.
Oct 23, 2002
110
US
I have a form that loads a subform. The subform is based on a query. How do I count the number of records that the subform loads and then execute a procedure if it loads more than 1 record?
 
You can refer to the recordcount property of the recordset for the subform.
 
It depends on where you are referring to it from. Let us say the main form.

[tt]Me.[Subform Control Name].Form.Recordset.RecordCount[/tt]
 
You are losing me. Do you mean (?):

Me.RecordSource ="Select ThisFieldOnly From ATable
 
Several examples...

E#1
myrecordcount = dcount("myfield","mytable","myfilter")
E#2
set rs = me.subform.form.recordsetclone
rs.movelast
myrecordcount = rs.recordcount
E#3
' Modified form recordsource...
Set rs = db.openrecordset("SELECT count(myfield) FROM mytable WHERE myfilter", dbopensnapshot)
myrecordcount = rs(0)

My preference is #3, because it is very fast when you are loading 10K+ records, but #2 is more applicable. I hate using the Dcount/Dsum functions.

I did not suggest recordcount because my prior experience told me that recordcount was not instantly reliable. I believe it was depending on when JET got done assessing the size of the recordset.

Gary
gwinn7
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top