Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
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 February 2nd, 2005, 09:33 AM
Registered User
 
Join Date: Feb 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to tseng
Default Help!! i need to get a closest match

I need to get he closest weight match from one table to another.
someone inputs a "weightrequired"in the "order" table.
Then in another table called "paint".
There is a "weight" column. The "weightrequired" must get the closest match to the "weight" and then put this into the "order" table.
I understand that it is quite easy but i can get my head around it.
It would be ebst to do it in VBA and use a loop to get the closest match but i haven't a clue how to do this as i am used to graphic design. This is the first time i have used access.
Thankyou for any help in advance.

 
Old February 2nd, 2005, 11:19 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

this will get the closest match
SELECT TOP 1 <FIELDS>
FROM <TABLE>
ORDER BY Abs(<Weight> - <WeightRequired>) ASC
 
Old February 2nd, 2005, 02:05 PM
Registered User
 
Join Date: Feb 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to tseng
Default

So i put that as a module. in VBA.

 
Old February 4th, 2005, 07:44 PM
Registered User
 
Join Date: Feb 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to tseng
Default

I have never used access before so i havent got a clue how to configure VB 6.0 codes for VBA.
as weight_given and turkey_weight are actually from a table. (see above posts)
And also this code needs to go down the table and try all the values from the table. The table will only have about 40 entries so it is quite easy to put in a simple code like this.
please help...


Code:
Function find_match()
Dim weight_given As Integer
Dim weighttemp As Integer
weight_given = Val(text1.Text)
Turkey_weight= Val(text2.text)
Do weight_given -Turkey_Weight
result = weightless
weighttemp = weightless \ 1   'to make sure all results are postive else it won't find the closest

weight_given -turkey_weight2
If result > weighttemp Then Loop
If result < weightemp Then weighttemp = result
Loop Until weighttemp = 0 'i will ensure there is a value of 0 at the bottom of tableweight

temp = actual_weight 'needs to be put into the invoice table somehow
End Function





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT Match Mitali XSLT 7 July 24th, 2008 03:39 AM
template match doesnt match the required node Tomi XSLT 2 March 12th, 2007 06:24 AM
Match by attribute. ole_v2 XSLT 6 November 11th, 2006 10:24 AM
Match records bram_code VB Databases Basics 1 May 5th, 2006 10:36 AM
match containing variable csbdeady XML 1 October 25th, 2004 05:57 AM





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