10 Labels... for loop?!

mattloflin

Question Askin Lad
Local time
Yesterday, 20:20
Joined
Dec 22, 2007
Messages
31
Im creating labes 10 to a sheet. I need code that will let me add a number to each label...

simply put

for x = 1 to 10
Reports!rptTest.txtPart(x) = "test" & x
next x

I have textboxes -> txtPart 1 thru 10 (txtpart1, txtpart2...) that i need to read "test" and the value of x

so when I click preview it should generate the labels and the for loop should go txtPart1 = "test1" txtPart2 = "test2"

now I have tried this in the onformat event and it doesn't read onformat on this report unless i need to call it. So basically HOW CAN I DO THIS FROM A FORM ?!?!?!

You guys rock!
 
Im creating labes 10 to a sheet. I need code that will let me add a number to each label...

simply put

for x = 1 to 10
Reports!rptTest.txtPart(x) = "test" & x
next x

I have textboxes -> txtPart 1 thru 10 (txtpart1, txtpart2...) that i need to read "test" and the value of x
Well, I don't know what else is involved here, but the (general) code you are looking for is probably this (assuming you can add numbers to a digit that is already declared a string, and I believe you can):
Code:
dim c as control
  dim x as string

  for each c in me.controls
    if type of c is textbox then
      if c.name = "txtpart" & x then
        c = "test" & x
      end if
    end if
x = x + 1
  next
You can't assign different data types to a value of anykind, so the "For x = 1 to 10" will not work, because you will be trying to concat the integer value of 'x' with the string value "test". I guess it might be possible to put your integer values into an array, and redim it when you need it to be a string, but that seems like too much work.
 
Last edited:
Hi,

Try this, its not tested but it should work.

Code:
Dim textstring As String
Dim teststring As String
For X = 1 To 10
textstring = "textpart" & X
teststring = "test" & X
Reports("rptTest").Controls(textstring)= Teststring
Next X

Let me know

Garry
 

Users who are viewing this thread

Back
Top Bottom