Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 07-01-2014, 10:49 AM   #1
aschachtel
Newly Registered User
 
Join Date: Jun 2014
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
aschachtel is on a distinguished road
Smile Help Writing a Loop

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

aschachtel is offline   Reply With Quote
Old 07-01-2014, 11:16 AM   #2
aschachtel
Newly Registered User
 
Join Date: Jun 2014
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
aschachtel is on a distinguished road
Smile 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...
aschachtel is offline   Reply With Quote
Old 07-01-2014, 11:25 AM   #3
jdraw
Super Moderator
 
jdraw's Avatar
 
Join Date: Jan 2006
Location: Ottawa, Ontario, Canada;West Palm Beach, Florida
Posts: 12,238
Thanks: 93
Thanked 2,026 Times in 1,973 Posts
jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light
Re: Loop Help

What are you trying to do in plain English?

__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
jdraw is offline   Reply With Quote
Old 07-01-2014, 11:31 AM   #4
Rx_
Nothing In Moderation
 
Rx_'s Avatar
 
Join Date: Oct 2009
Location: Denver, Colorado
Posts: 2,803
Thanks: 636
Thanked 337 Times in 307 Posts
Rx_ has a spectacular aura about Rx_ has a spectacular aura about Rx_ has a spectacular aura about
Lightbulb Re: Help Writing a Loop

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.
__________________
Were you lucky enough to get an answer? Please mark your question as [SOLVED] The original poster can go to Thread Tools to mark it as Solved.

Quotation Thomas Jefferson: "Peace is that brief glorious moment in history when everybody stands around reloading."

There are 2 Kinds of Countries on this Planet
1. Those that use the Metric System
2. Those that had a man walk on the moon

Denver, Colorado - The "Mile High City" - non-metric!
Rx_ is offline   Reply With Quote
Old 07-01-2014, 11:43 AM   #5
aschachtel
Newly Registered User
 
Join Date: Jun 2014
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
aschachtel is on a distinguished road
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 is offline   Reply With Quote
Old 07-01-2014, 11:46 AM   #6
aschachtel
Newly Registered User
 
Join Date: Jun 2014
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
aschachtel is on a distinguished road
Re: Help Writing a Loop

this doesnt work. it gets a error "no current record"

also, i changed your code to .movenext...not movefirst
aschachtel is offline   Reply With Quote
Old 07-01-2014, 12:07 PM   #7
aschachtel
Newly Registered User
 
Join Date: Jun 2014
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
aschachtel is on a distinguished road
Re: Help Writing a Loop

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?

aschachtel is offline   Reply With Quote
Old 07-01-2014, 12:13 PM   #8
jdraw
Super Moderator
 
jdraw's Avatar
 
Join Date: Jan 2006
Location: Ottawa, Ontario, Canada;West Palm Beach, Florida
Posts: 12,238
Thanks: 93
Thanked 2,026 Times in 1,973 Posts
jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light
Re: Loop Help

I recommend you read this to get better understanding of recordsets.
http://www.utteraccess.com/wiki/inde..._for_Beginners
Good luck.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
jdraw is offline   Reply With Quote
Old 07-01-2014, 12:57 PM   #9
Rx_
Nothing In Moderation
 
Rx_'s Avatar
 
Join Date: Oct 2009
Location: Denver, Colorado
Posts: 2,803
Thanks: 636
Thanked 337 Times in 307 Posts
Rx_ has a spectacular aura about Rx_ has a spectacular aura about Rx_ has a spectacular aura about
Lightbulb Re: Help Writing a Loop

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
For MyCounter = 1 To 100 
    Me.Controls("sn" & MyCounter ).Caption = valuearray(MyCounter ) 
Next CT
__________________
Were you lucky enough to get an answer? Please mark your question as [SOLVED] The original poster can go to Thread Tools to mark it as Solved.

Quotation Thomas Jefferson: "Peace is that brief glorious moment in history when everybody stands around reloading."

There are 2 Kinds of Countries on this Planet
1. Those that use the Metric System
2. Those that had a man walk on the moon

Denver, Colorado - The "Mile High City" - non-metric!
Rx_ is offline   Reply With Quote
Old 07-01-2014, 01:58 PM   #10
vbaInet
AWF VIP
 
Join Date: Jan 2010
Location: U.K.
Posts: 26,374
Thanks: 0
Thanked 2,423 Times in 2,389 Posts
vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all
Re: Help Writing a Loop

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
vbaInet is offline   Reply With Quote
Old 07-01-2014, 03:22 PM   #11
vbaInet
AWF VIP
 
Join Date: Jan 2010
Location: U.K.
Posts: 26,374
Thanks: 0
Thanked 2,423 Times in 2,389 Posts
vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all
Re: Loop Help

Duplicate thread:
http://www.access-programmers.co.uk/...d.php?t=266331
vbaInet is offline   Reply With Quote
Old 07-01-2014, 04:04 PM   #12
MarkK
Super Moderator
 
MarkK's Avatar
 
Join Date: Mar 2004
Location: Vancouver BC
Posts: 7,761
Thanks: 10
Thanked 1,290 Times in 1,227 Posts
MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all
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

__________________
formerly known as lagbolt | Windows 10 | Access 2010 | Visual Studio 2013 | "Institutions have a vested interest in perpetuating the problems to which they are the solution." - Clay Shirky
MarkK is offline   Reply With Quote
Reply

Tags
loop , syntax

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
resume loop at next loop wazz Modules & VBA 14 10-07-2017 08:36 PM
VB Access Loop Problem: exits loop prematurely even if conditions are met kapaw Modules & VBA 5 08-24-2015 03:49 AM
VB Loop thu record ansd loop thu table pekajo Modules & VBA 2 01-17-2013 01:15 AM
For Next Loop ingores first loop WineSnob Modules & VBA 8 04-26-2012 02:28 PM
Loop Problem... Need loop inside loop maybe...? mikebaldam Modules & VBA 6 08-03-2005 12:55 AM




All times are GMT -8. The time now is 04:30 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World