Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 19th, 2006, 02:23 PM
Authorized User
 
Join Date: Dec 2006
Location: Florence, KY, USA.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to FalseParadigm
Default Using Controls within a For...Next loop

I have ran into an interesting situation. Using a Form, the user will enter up to 20 records at a time (like an order form where there will be 20 part numbers, 20 descriptions, 20 unit proces, etc). I named them all with the same convention: txtQty0, txtQty1, txtQty2, and so on.

Because there is some math involved, I have arrays for the data to avoid writing the same formula (which is quite large and complex) over and over. However, I found that I need to reference the values of the controls themselves in my formula.

Is there a way to handle controls in the same way as other variables (such as arrays) so that I can use them in my For...Next loops? I would love to do something like this:

Code:
Dim x As Integer
Dim aQty(19) As Integer

For x = 0 to 19
   aQty(x) = txtQty(x).Value
Next x
But I know that this isn't possible. Does anyone know if there is a another way to pull this off?

I tried to explain what I'm trying to do as best as I could, so if anyone needs any clarification, please let me know.

--------------------------------
Ben

"It's my way, or the Hemingway."
--------------------------------
__________________
<hr noshade size=\"1\">\"We do things my way, or the Hemingway...\"
Reply With Quote
  #2 (permalink)  
Old December 20th, 2006, 05:42 AM
Friend of Wrox
 
Join Date: Sep 2003
Location: Salisbury, Wiltshire, United Kingdom.
Posts: 155
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to leehambly
Default

Yeah it is possible...

You need to build the control name in a string and then identify the control using the string, so something like...

strTempControlName = txtQty & x
aQty(x) = me.Controls(strTempControlName).Value

to replace your line

aQty(x) = txtQty(x).Value

Should do the trick, I think.
Reply With Quote
  #3 (permalink)  
Old December 20th, 2006, 09:55 AM
Authorized User
 
Join Date: Dec 2006
Location: Florence, KY, USA.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to FalseParadigm
Default

Thank you, this works perfectly. I was unaware that Me.Controls could be used in such a way. This will certainly help me out in other areas of my app. Thank you again. Its like an early Christmas present!

--------------------------------
Ben

"It's my way, or the Hemingway."
--------------------------------
Reply With Quote
  #4 (permalink)  
Old December 20th, 2006, 10:01 AM
Friend of Wrox
 
Join Date: Sep 2003
Location: Salisbury, Wiltshire, United Kingdom.
Posts: 155
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to leehambly
Default

This is especially useful in reporting, you can build control arrays and really do some on-the-fly formatting... Merry Xmas!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
User controls' content: Chapter 2 User Controls AGS BOOK: Professional ASP.NET 2.0 Server Control and Component Development ISBN: 978-0-471-79350-2 10 July 26th, 2007 05:36 AM
loop through controls and master page fraperz ASP.NET 2.0 Professional 2 June 19th, 2007 01:25 PM
For...Next Loop msmagied Classic ASP Components 1 August 2nd, 2004 06:01 PM
Loop thru controls Mitch Access 2 December 23rd, 2003 02:14 PM
nested while loop doesn't loop hosefo81 PHP Databases 5 November 12th, 2003 08:46 AM



All times are GMT -4. The time now is 05:24 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.