Solved

what is the syntax

Posted on 2000-02-19
15
146 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now