Avatar of dbote
dbote
Flag 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
Microsoft Word

Avatar of undefined
Last Comment
dbote

8/22/2022 - Mon
Chris Bottomley

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

Chris
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.
Chris Bottomley

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
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER CERTIFIED SOLUTION
dbote

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
dbote

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