I will try to simplify. I have a 100 buttons on a form. The buttons
all have unique names and are NOT in an array. The name of each button is
displayed in its caption. There is also a textbox (Text1). When the user
types in the name of one of the hundred buttons (eg. "Command1") into Text1,
and then presses enter, the caption of the button whose name he typed should
now read "changed".
This is the code I have, but it does not work:
Dim TargetButton As Control
Dim AA As String
AA = Text1.Text
Set TargetButton = AA
TargetButton.Caption = "Changed"
This code comes up with a type mismatch error, and I don't know what to
do. I figure there has got to be a way to hold the name of a button in a
variable. Could someone please help me solve this problem?
-Paul
Steve Gerrard - 30 Jun 2004 02:59 GMT
> Dim TargetButton As Control
> Dim AA As String
> AA = Text1.Text
>
> Set TargetButton = AA
> TargetButton.Caption = "Changed"
Set TargetButton = Controls(AA)
Controls is a collection of all the controls on the form. Note that you
will also want to do some error handling, in case there is no control of
that name, or it is a control that does not have a caption.