Help Writing a Loop (1 Viewer)

aschachtel

Registered User.
Local time
Yesterday, 17:02
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
 

aschachtel

Registered User.
Local time
Yesterday, 17:02
Joined
Jun 24, 2014
Messages
15
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...
 

jdraw

Super Moderator
Staff member
Local time
Yesterday, 20:02
Joined
Jan 23, 2006
Messages
15,379
Re: Loop Help

What are you trying to do in plain English?
 

Rx_

Nothing In Moderation
Local time
Yesterday, 18:02
Joined
Oct 22, 2009
Messages
2,803
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. ;)
 

aschachtel

Registered User.
Local time
Yesterday, 17:02
Joined
Jun 24, 2014
Messages
15
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...
 

aschachtel

Registered User.
Local time
Yesterday, 17:02
Joined
Jun 24, 2014
Messages
15
this doesnt work. it gets a error "no current record"

also, i changed your code to .movenext...not movefirst
 

aschachtel

Registered User.
Local time
Yesterday, 17:02
Joined
Jun 24, 2014
Messages
15
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?
 

Rx_

Nothing In Moderation
Local time
Yesterday, 18:02
Joined
Oct 22, 2009
Messages
2,803
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
 

vbaInet

AWF VIP
Local time
Today, 01:02
Joined
Jan 22, 2010
Messages
26,374
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
 

MarkK

bit cruncher
Local time
Yesterday, 17:02
Joined
Mar 17, 2004
Messages
8,180
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

Top Bottom