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
  Next
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,

dbote
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"

Chris
Avatar of dbote

ASKER

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?

Chris
ASKER CERTIFIED SOLUTION
Avatar of dbote
dbote
Flag of United States of America image

Link to home
membership
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

ASKER

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