Continuous Subforms

  • Thread starter Thread starter Dave Alger
  • Start date Start date
D

Dave Alger

Hi all,

I understand that when a subform displays records in continuous form access
is creating various instances of the controls in the detail section of the
form. My question is how can I access the values in these instances?

For instances if there's a txtValue control on my form which displays the
"VALUE" field how can I cycle through all the records displayed and use the
values of txtValue for each record in my code? Is it some form of array?

I hope that makes some sense. Thanks in advance for those taking time to
help.

regards,
Dave
 
Unfortunately, there is not multiple instances of the controls.

So, you can't really reference the controls like an array.

however, for all forms (even non continues forms), you can certainly
process, or "traverse" the reocrdset for that form.

So, to work with the data...you are free to do so.

If you reference any control in the continues sub form, it will return the
value of the current record.

Each form of course does have a recordsetClone

So, the "general" program loop to process a reocrdset is:

dim rstRecs as dao.recordset
dim strSql as string

strSql = "select * from customer where City = 'Edmonton'"

set rstRecs = currentdb.OpenRecordSet(strSql)

do while rstRecs.EOF = false
debug.print "compnay name is " & rstRecs!CompanyName
rstRecs.MoveNext
loop
rstRecs.Close
set rstRecs = nothing

so, the above is very much like an "array" of data. The above would print
all companies that have city of Edmonton.

For the sub-form, you can process the data like:

(I am assume this code is on the main form).


dim rstRecs as dao.RecordSet
dim curTotal as currency

set rstRecs = MySubForm.form.RecordsetClone

do while rstRecs.EOF = false
cutTotal = curTotal + rstRecs!InvoiceAmount
rstRecs.MoveNext
loop
rstRecs = nothing
msgbox "total for sub form is = " & curTotal

So, you can use the reocdset clone to traverse the reocrds that belong to
any form...including a sub form. The above would show the total for a field
called InvoiceAmount.
 
Back
Top