Solved

what is the syntax

Posted on 2000-02-19
15
148 Views
Last Modified: 2010-05-02
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
Comment
Question by:keithtbe
  • 5
  • 4
  • 3
  • +2
15 Comments
 
LVL 12

Expert Comment

by:mark2150
ID: 2538124
try:

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

M
0
 
LVL 6

Expert Comment

by:Marine
ID: 2538132
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
 
LVL 1

Expert Comment

by:mmips
ID: 2538403
Marine... I think you mean 0 to 12...for 13 elements
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 6

Expert Comment

by:Marine
ID: 2538406
opps you correct !!
0
 

Author Comment

by:keithtbe
ID: 2539381
Edited text of question.
0
 
LVL 12

Expert Comment

by:mark2150
ID: 2539648
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
 

Accepted Solution

by:
KevinHo earned 25 total points
ID: 2542950
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
 

Author Comment

by:keithtbe
ID: 2544534
if i dun want to use array textboxes
is that a possible way to make the text boxes invisible?
0
 
LVL 12

Expert Comment

by:mark2150
ID: 2544561
Yes, but a control array is cleaner and more managable.

M
0
 
LVL 6

Expert Comment

by:Marine
ID: 2544589
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
 
LVL 12

Expert Comment

by:mark2150
ID: 2544630
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
 
LVL 6

Expert Comment

by:Marine
ID: 2544639
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
 

Expert Comment

by:KevinHo
ID: 2545229
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
 
LVL 12

Expert Comment

by:mark2150
ID: 2545850
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
 

Author Comment

by:keithtbe
ID: 2546708
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question