Help Writing a Loop

aschachtel

Registered User.
Local time
Yesterday, 20:05
Joined
Jun 24, 2014
Messages
15
I want to turn this into a loop instead of writing it out 13 times...

Can someone help me?



rstBrickAttributeValues.MoveFirst
strBAV = rstBrickAttributeValues!CoreAttributeSpecificTypeDescription

Me.lbl.Caption = strBAV



rstBrickAttributeValues.MoveNext
strBAV = rstBrickAttributeValues!CoreAttributeSpecificTypeDescription

Me.lbl1.Caption = strBAV



rstBrickAttributeValues.MoveNext
strBAV = rstBrickAttributeValues!CoreAttributeSpecificTypeDescription

Me.lbl2.Caption = strBAV
 
Loop Help

I want to turn this into a loop instead of writing it out 13 times...

Can someone help me?



rstBrickAttributeValues.MoveFirst
strBAV = rstBrickAttributeValues!CoreAttributeSpecificTypeD escription

Me.lbl.Caption = strBAV



rstBrickAttributeValues.MoveNext
strBAV = rstBrickAttributeValues!CoreAttributeSpecificTypeD escription

Me.lbl1.Caption = strBAV



rstBrickAttributeValues.MoveNext
strBAV = rstBrickAttributeValues!CoreAttributeSpecificTypeD escription

Me.lbl2.Caption = strBAV



rstBrickAttributeValues.MoveNext
strBAV = rstBrickAttributeValues!CoreAttributeSpecificTypeD escription

Me.lbl3.Caption = strBAV

etc...
 
Re: Loop Help

What are you trying to do in plain English?
 
Code:
Dim MyCounter as Integer
For  MyCounter = 1 to 13 
  rstBrickAttributeValues.MoveFirst
  strBAV = rstBrickAttributeValues!CoreAttributeSpecificTypeD escription
 
  Me.lbl.Caption = strBAV
 
Next MyCounter

The For Next Loop runs a specific amount of times. The 1 and 13 can also be variables to be assigned based on the need.
The for next loop can prevent infinate loops.

However, with the new overclocked i7 5th generation Haswell processor, Intel boasts the infinate loop only takes a couple of minutes now. ;)
 
Re: Loop Help

I have a record set that is based on a query i ran (strBAV)...now, im trying to take the "Core Attribute Value" field from this query record set and fil out 13 labels with the 13 results from this field. So say the results are "red," "orange," "yellow," etc...those records become the captions for label1 (lbl1), label2 (lbl2), label3 (lbl3), etc...
 
this doesnt work. it gets a error "no current record"

also, i changed your code to .movenext...not movefirst
 
I think it might be because "lbl" is not sufficient? There are 13 labels to be filled out and they are named lbl, lbl1, lbl2, lbl3, lbl4, lbl5, etc...your code does not address that?
 
It will probably be something like this with the Controls collection.

Code:
 rstBrickAttributeValues.MoveFirst
  strBAV = rstBrickAttributeValues!CoreAttributeSpecificTypeDescription
  Me.lbl1.Caption = strBAV
 
Dim MyCounter as Integer
For  MyCounter = 2 to 13 
  rstBrickAttributeValues.MoveNext
  strBAV = rstBrickAttributeValues!CoreAttributeSpecificTypeDescription 
  Me.Controls("lbl" & MyCounter).Caption = strBAV 
Next MyCounter
 
'Basically like this
[COLOR=#0000ff]For[/COLOR] MyCounter = 1 [COLOR=#0000ff]To[/COLOR] 100 
    Me.Controls("sn" & MyCounter ).Caption = valuearray(MyCounter ) 
[COLOR=#0000ff]Next[/COLOR] CT
 
By the way, are you using ADO or DAO? I suspect DAO.

So we could do it this way:
Code:
dim i as integer

with rstBrickAttributeValues
    .moveLast
    .moveFirst
    
    for x = 1 to .recordCount
        me.controls("lbl" & i).caption = nz(!CoreAttributeSpecificTypeDescription, vbnullstring)
        .movenext
    next
end with
 
aschachtel, please don't post the same question in multiple sections of the forum. Multiple-posting like that waters down that value of the forum, and wastes the time of people offering help.
Thanks for you consideration in this regard,
Mark
 

Users who are viewing this thread

Back
Top Bottom