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

Change properties of a rectangle named in a field. 1

Status
Not open for further replies.

Hanss

Technical User
Feb 15, 2001
85
CH
I have a form "form1 with an unbound text box: "pos2". I also have a number of rectangles(a1, a2, a3 etc.). I also have a command button "Command59".

I would like to enter the name of a rectangle in field "pos2" and when command59 is clicked, change the back color of the rectangle that was entered in field "pos2".

Here is what I have tried. I entered the name of rectangle a1 in field "pos2" and clicked on the button using the following code:

Private Sub Command59_Click()

Forms!form1![pos2].BackColor = "16744448"

End Sub

The problem is that clicking on the button only changes the backcolor of field "pos2" and not rectangle "a1".

I have been reading "VBA for dummies" but it has not helped me much...

Would appreciate any help!

Kind regards,
Hanss
Zurich, Switzerland
 
and what about this ?
Me.Controls(Me!pos2).BackColor = 16744448

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I think you need to capture pos2's value as a string. Try something like this perhaps?

Code:
Private Sub Command59_Click()
dim tstr as string

tstr = Forms("form1").Controls("pos2").value

Forms("form1").Controls("""" & tstr & """").BackColor = "16744448"
    
End Sub

Hope this helps,

Alex

A wise man once said
"The only thing normal about database guys is their tables".
 
Thank you both very much for your help! The PHV code works fine. I tried to get your code going as well Alex but got this error:

"ambigious name detected"

Many Thanks!
Hanss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top