Form/Subform Count

  • Thread starter Thread starter brian
  • Start date Start date
B

brian

I have a form with a corresponding subform. The subform
is currently showing 23 records with such fields as date
and name. I would like to establish an unbound text box
in the main form that shows a count of the records in the
subform. I have posted this question the other day and
received some good ideas but I still cannot get it to
work. It is my understanding to use a count function of
sorts in the control box of the unbound text box. At
present I am using "=Count(Forms![frmTabDeposit subform]!
Name)". Any suggestions?
Thanx.
 
Are you filling the subform through code?

If not and you are using a table, in the on load event in
the main form, open up the table, get a recordcount, save
it to the text box and close the table up again.

Are you adding records? If so and you want the value to
update, then put the recordcount procedure as a public
function that can be called from anywhere.

Code:
Public Sub RecordCounting()
Dim rst as new adodx.recordset
with rst
.open "tbl_Name", , CurrentProject.Connection,
adOpenKeyset, adLockOptimistic
form_FORMNAME.TextBoxControlName = .recordcount
.close
end with
End Sub


You could make it fancier and send it the name of the
table if you want it count records in different table and
you could also send it the name of the control you want
it to post to.

Public Sub RecordCounting(Tablename as string, Cntl as
Control) ... the code changes a bit ... if you want a
little fun see if you can make it work!
 
Back
Top