• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 154
  • Last Modified:

what is the syntax

for i=0 to 12 step 1
with rs
.edit
.fields("ww & i &")=text(i).text
.update
end with
next i

the problem is the syntax ("ww & i &")
how to write the code? what is the correct syntax to pass the variable i into the code?

another problem also regarding syntax

how to write a for ........ loop code
i have 52 textboxes which name
ww1,ww2,ww3.......................ww52
i want to set them to invisible
how to use the for ......loop command to write for the code?
pls help
pp301t (form name)
ww1(textbox name)
the code i write is
for i=1 to 52 step 1
pp301t.ww & i.visible=false
it cannot work
what is the code
can anybody tell me
thanks u
0
keithtbe
Asked:
keithtbe
  • 5
  • 4
  • 3
  • +2
1 Solution
 
mark2150Commented:
try:

..fields("ww" & trim( str( i ) ) ) = ...

M
0
 
MarineCommented:
OK you probably using DAO as your access method since ADO doesn't have it.
The problem you having now as follows. Your code starts looping from element 1. The fields collection have a base of 0. So if you have a conrol array of textboxes they must correspond to the fields collection in your table. YOu have to start you looping from 0.
for i = 0 to 13
rs.edit
rs(i) = text1(i).text
rs.update
next
this code should work since the i will be on the same level as field collection. I hope i am making sence having troulbe explaining this.
Now what is pp and that other stuff i don't understand you didn't give info on it.be more specific to make these textboxes visible or not just loop though them and set them to false if thas what you are trying to do.
0
 
mmipsCommented:
Marine... I think you mean 0 to 12...for 13 elements
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
MarineCommented:
opps you correct !!
0
 
keithtbeAuthor Commented:
Edited text of question.
0
 
mark2150Commented:
For you text boxes you should be using a control array. This is what arrays are for. Delete all but the first one and then start copying them again. When it asks "You already have a control named ... do you want to make an array?" say YES (or simply set the .Index property of the first control to '0')

In either case when you have the controls rebuilt you can code:

For Ndx = 0 to MyControl.Ubound
  Mycontrol(ndx).Visible = False
Next Ndx

M
0
 
KevinHoCommented:
For the problem of making the textboxes invisible use the controls array. To loop through and make the appropriate controls invisible.

i.e.

Dim conTemp As Control

For Each conTemp In Form1

If TypeOf conTemp Is TextBox And  
Left(conTemp.Name, 2) = "ww" Then

        conTemp.Visible = fasle

End If

Next

This is one solution. You can also make the textboxes a control array and use a normal for next loop.
0
 
keithtbeAuthor Commented:
if i dun want to use array textboxes
is that a possible way to make the text boxes invisible?
0
 
mark2150Commented:
Yes, but a control array is cleaner and more managable.

M
0
 
MarineCommented:
Maybe somethign like this.

Dim control As TextBox
For Each control In Form1.Controls
    If TypeOf control Is TextBox Then
        control.Visible = False
    End If
Next
0
 
mark2150Commented:
KevinHo's answer is more general. Marines will turn all text boxes invisible, KevinHo's answer will just do those with matching names. My solution will do all elements of a control array.

Take your pick.

M
0
 
MarineCommented:
I would go with your suggestion Mark because its more logical i suggested my example only because he didn't want to do it control array.
0
 
KevinHoCommented:
I don't disagree with Mark or Marine, a control array containing the text boxes you want invisible is the neater and better solution. But if you don't want to do this then using the controls array on the form is an alternative solution.
0
 
mark2150Commented:
Yep. They're all basically equivalent solutions. Pick one that suits your current app. Naturally I'm biased towards my answer, but KevinHo's is nice and Marines works as well.

Keithtbe, we haven't heard from you in a bit...

M

0
 
keithtbeAuthor Commented:
i really appreciate of what u suggested
because i have already set my form
it is really a big problem to change all the thing to array
so i really hope that that is a way to write a loop code to ease my problem
sigh
another thing
i really have a big problem of accepting those answer since all are well
another thing is this code can't work
Dim control As TextBox
                   For Each control In Form1.Controls
                       If TypeOf control Is TextBox Then
                           control.Visible = False
                       End If
                   Next
these maybe set all the textbox to invisible but what i want is part of it
but anyway
thanks u for ur help
so who should i give the point? can i give to u all?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now