For each ctl in SUBFORM?

charityg

Registered User.
Local time
Today, 02:25
Joined
Apr 17, 2001
Messages
634
I need to check some criteria for some textboxes on my form (containing 5 subforms). I have set the tag property to do this and I want to loop through the control collection and verify some things. I know how to achieve this with my main form controls, but how do I include all of the controls on the subforms (which are themselves controls). I've looked into forms collections and parent properties, but nothing seems to fit. This is what I have:
For each frm in Forms
for each ctl in frm
if ctl.tag="whatever" then
blah blah
exit sub
endif
next ctl
next frm

But since I only have the Main form open, that seems to be the only form in my Forms collection. HELP! I know this code can be written neatly!!
 
i don't know whether this has any relevance but I did notice that it is possible to assign an object variable to a subform

Dim subfrm as SubForm

for each ctl in subfrm
if ctl.tag="whatever" then
blah blah
exit sub
endif
next ctl
next subfrm

note; I haven;t tried it because I don't have any test db's at the moment.

Hope that helps some.

Ian
 
Thanks for trying, but that doesn't work.
 
Look in help under "Form Property".

These properties are typically used to refer to the form or report contained in a subform or subreport control. For example, the following code uses the Form property to access the OrderID control on a subform contained in the OrderDetails subform control.

Dim intOrderID As Integer
intOrderID = Forms!Orders!OrderDetails.Form!OrderID

hth,

Doug.
 
Thanks for your help! I was hoping for an ingenious idea to make the code simple, but alas I went with.

dim subfrm as subform
dim ctl as control
for each ctl in me.control
blah blah
next ctl

select case status
case whatever
subfrm=me!subformname
end select

for each ctl in subfrm
blah blah
next ctl

Since I only need to search one of the subforms based on the status of the record, this way works, and it's not too messy.

You guys are great though, thanks again for the input!

~Charity
 

Users who are viewing this thread

Back
Top Bottom