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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For Each loop? 1

Status
Not open for further replies.

dcurtis

Technical User
May 1, 2003
273
US
I am trying to toggle some controls on a form from visible = True to Visible = False when a use clicks a button. The routine checks to see if the control is currently visible, if so, makes it invisible, and vice versa with the others.

I tried to use a For Each loop, but when it gets to the last button, which will always be visible (and subsequently has the focus) it errors. I can't set the visible property to false on a control that has the focus. How do I tell access to check all but last control?

----
Access 2002 on a mixed Windows OS network.
 
You could for instance use the .name of the control, or the .tag property of the control

[tt]dim ctl as control
for each ctl in me.controls
if ctl.controltype = actextbox or ctl.controltype = accombobox then
if ctl.name <> "NameOfControl" then
ctl.visible = not ctl.visible
end if
end if
next ctl[/tt]

Roy-Vidar
 
You could just bypass the error
[tt]
On Error Resume Next
ctl.Visible = FALSE
On Error GoTo 0
[/tt]
 
Roy, it works great so far, but I also have some check boxes and radio buttons (part of an option group) and all the associated labels.

Would I modfy the "if ctl.controltype = actextbox....." to include the other types?
 
I guess I posted just a little too quickly. I figured out how to do labels and check boxes, but can't get the option groups and radio buttons.
 
Best way is to press F1 while the cursor is within controlltype - they should "magically" appear;-)

To add more controltype to the same test statement, perhaps:

[tt]Select case ctl.controltype
case actextbox, accombobox, accheckbox, acoptiongroup
' perform...
End select[/tt]

- or individual cases per controltype/groups of...

But if you perform this on ALL controls except the one, you could try without any criterias, just do the toggling of the visible property.

Roy-Vidar
 
Roy, thanks for the help. I found the list, and was able to make it work. Here are stars for your time and effort.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top