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 November 12th, 2006, 09:59 AM
Authorized User
 
Join Date: Oct 2006
Location: , , .
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default Referencing Unbound fields with variables

I have 10 fields on a subform, named TP1, TP2, .... thru TP10.

I want to sum the value of each of the 10 fields.

I would like to use a loop to do this, like the following:

Dim p As Integer
Dim PalletCount As Single

For p = 1 To 10
    PalletCount = PalletCount + Eval("TP" & p & ".Value")
    Debug.Print PalletCount
Next p
I get the message "Microsoft Access can't find the name 'TP1' you entered in the expression.

I would like to avoid the following more explicit method:

PalletCount = TP1 + TP2 + TP3 + TP4 + TP5 .... + TP10



Reply With Quote
  #2 (permalink)  
Old November 12th, 2006, 11:11 AM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

the code is not actually referencing the textbox on the form.

try the following code which will set a reference to the textbox based on the name each time you go around the loop. then you can get the value:

Dim p As Integer
Dim PalletCount As Single
Dim t As TextBox

For p = 1 To 10
    Set t = Me.Controls("TP" & p)
    PalletCount = PalletCount + Eval(t.Value)
    Debug.Print PalletCount
Next p



Reply With Quote
  #3 (permalink)  
Old November 12th, 2006, 11:55 AM
Authorized User
 
Join Date: Oct 2006
Location: , , .
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Wow, thanks. Amazing how such a simple little thing can make the difference, I had been struggling with this for a while.

Now I have to go back and see what other routines should be utilizing this.

Thanks a ton!

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
Number of variables referencing an Object Muyavil Java Basics 3 April 11th, 2009 11:02 PM
Referencing Fields using VBScript in Outlook 2000 stelhead All Other Wrox Books 0 January 3rd, 2008 12:04 PM
Referencing Fields within Tab Control Pages -Help TomW Access VBA 1 October 30th, 2006 01:31 PM
Unbound Fields on a continuous form phil.t Access 0 October 5th, 2004 07:44 PM
can anybody help me in using unbound fields in CR prasan BOOK: Professional Crystal Reports for VS.NET 0 July 20th, 2004 12:41 AM



All times are GMT -4. The time now is 01:13 AM.


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