Setting 1 obj = another obj where each obj names change

G

Guest

Can you create two variables that build objects names and change one object
value by setting them equal to each other. I have tried two string vars and
it just replaces one string with the other instead of changing the objects
value.

The objects I want to change are text fields on a form.

This is what I have tried.
Dim strObj1 as string
Dim strObj2 as string
Dim counter as integer
loop until counter = 10

strObj1 = "Me.ObjName" & counter & "a"
strObj2 = "Me.ObjName" & counter & "b"

strOjb1 = strObj2

Counter + 1
end loop
I have also tried using the set command.

strOjb1 end up with the value: "Me.ObjName1a"
 
K

Ken Snell \(MVP\)

You can set the value of one string variable to the value in another string
variable by
strOne = strTwo
just as you show in your code.

Your post mentions changing the "text" values on a form -- but I don't see
any code steps in your post that are manipulating/using controls from a
form, so I must guess that there is more to your code than what you've
posted. Please post your actual code in its entirety, with respect to this
manipulation, so that we can assist you in debugging the code.
 
G

Guest

What on earth are you trying to achieve?!

For a start, remove the quotes around Me.ObjName

strOjb1 = strObj2 will always replace the contents of strOjb1 with the
contents of strObj2 (they are both String variables).

Steve
 
N

Norman Goetz

On Tue, 7 Aug 2007 09:26:03 -0700, MTTrader wrote:
Assuming you have twentytwo TextBoxes called
ObjName(0a)...ObjName(10b) and exceute in Formcode then
Dim strObj1 as string
Dim strObj2 as string
Dim counter as integer Do until counter = 10
strObj1 = "ObjName" & Cstr(counter) & "a"
strObj2 = "ObjName" & Cstr(counter) & "b"Me(strOjb1).Value= Me(strObj2).Value
Counter + 1 loop
I have also tried using the set command.
Each ObjName(n a) end up with the value of Obj2(n b)

HtH


Norman Goetz
 
G

Guest

I would like the change the first case statement into the second where I'm
looping through case statement so I don't have so much duplicate code. The
following repaints a form with over 100 text objects and the two line are
just part of a larger section of code.

Hope this clears up the confussion.
======== Current Code ===========
Case is 1 ...
Case is 54
Me.Match54a = Me.Match50b
Me.Match54a.BackColor = Me.Match50b.BackColor
Case is ... 64
end select
..movenext
=================================

============ Code objective ===========
Case is Counter
strObj1 = "Me.Match" & Counter & "a"
strObj2 = "Me." & rstTemp!MatchNum
strObj1 = strObj2
strObj1 & ".backcolor" = strObj2 & ".backcolor"
end select
..movenext
Counter = Counter + 1
=================================
 
G

Guest

you can do that with "me"? I'll give it a try. I'm currently in the middle
of something else but I'll get back to this when I'm done.
 
K

Ken Snell \(MVP\)

Look at using the Controls collection of the Me object:

Me.Controls("Match" & Counter & "a").BackColor

etc.

You can build a string that gives the name of the specific control, and use
it as the argument of the Controls collection reference.
 
G

Guest

Thanks Ken
--
Thanks,

JSY
MTTrader


Ken Snell (MVP) said:
Look at using the Controls collection of the Me object:

Me.Controls("Match" & Counter & "a").BackColor

etc.

You can build a string that gives the name of the specific control, and use
it as the argument of the Controls collection reference.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top