Link to home
Start Free TrialLog in
Avatar of dbote
dboteFlag for United States of America

asked on

VBA Controls Class

A UserForm for my MS Word  document has a button click that loops through the Controls on the form.

Private Sub cmdBack_Click()
  Dim ctrl As Control
  For Each ctrl In frmTest.Controls    
        If ctrl.Name = "fra1" Then ctrl.Visible = False
End Sub

Stepping through everything seems to work great BUT the control named fra1 never goes invisible.

In the Immediate window the control referenced with ctrl.visible returns False while the control referenced with fra1.visible returns True

If I change the code to fra1.visible = False the control does become invisible.

Why are these two code segments getting different results?

Thank you,

Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Is it finding that control on the form frmtest? ... try changing ctrl.visible = false to msgbox "here"

Avatar of dbote


In the For Each loop the control is definitely being found.  During debug I have cycled through stopping with each control and the control named fra1 definitely exists and is being found.
fra1 would work irrespective of caps whereas the name check would fail depending on vcase of the name ... so is the name definitely lower case?

Avatar of dbote
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dbote


I'm hoping that other will learn from my "mistake".