Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 2nd, 2009, 03:06 PM
ppenn
Guest
 
Posts: n/a
Default Loop through fields

Hi

I am reasonably familiar with the code to loop through dataset records and assign the values to variables, but I am currently stumped on something I am trying to do.
I have a form with various text boxes with points values in them and calculates a total of these points into another text box. I want to loop through the fields of a table and find a value that matches the total on the form, I then want to be able to display the result in another text box on the form.As an example imagine the table as follows
Field -- A--- B
Value -15- ABC
Value -25- DEF
Value -40- GHI

If the code loops through column A and if it finds the value on the form matches 25 then I want the value DEF to be able to be displayed on the form.
I thought that the code could run from the "After Update" event on a text box or combo box.
Thank you in advance, hoping you can understand my logic
Best regards
 
Old November 25th, 2009, 10:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

If you don't care if more than one value equals the total then you can use the DLookUp() function. After the total is calculated you can use it to find a record in the table where the value is equal to the total in question and pull the other data. For example:

Me.txtDesiredValue = DLookUp("[B]", "MyTable", "[A] = " & Me.txtTotal)
__________________
Greg Serrano
Michigan Dept. of Environmental Quality
Air Quality Division





Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop twice, then inside loop select nodes?? JohnBampton XSLT 2 March 9th, 2009 05:21 AM
XSLT 1.0 Multiple fields to multiple fields stlyz3 XSLT 11 February 9th, 2009 09:26 AM
Help with for-each loop athanatos XSLT 0 April 10th, 2006 07:20 PM
Using Forum fields select fields on the fly hellosureshkumar Crystal Reports 0 December 17th, 2004 08:20 AM
nested while loop doesn't loop hosefo81 PHP Databases 5 November 12th, 2003 08:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.