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
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access 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 Display Modes
  #1 (permalink)  
Old December 28th, 2004, 03:36 AM
Registered User
 
Join Date: Dec 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default calculations between records

Goodmorning,

I have a question concerning calculation between records in a table or query in access.
I need to extract a value in column x of record 1 from a value in column y in record 2 and then a value in column x in record 2 from a value in column Y in record 3 etc. Is there a way to do this is access or in VBA (has my preference), and how to handle end of file(Last record)

Thanks Paul

Reply With Quote
  #2 (permalink)  
Old December 28th, 2004, 08:40 AM
Friend of Wrox
 
Join Date: Nov 2003
Location: Lehigh Acres, FL, USA.
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

create a query and do your calculation

use this as a start
Code:
SELECT [Order Details].OrderID, [Order Details].Quantity, [Order Details].UnitPrice, Sum(CCur([UnitPrice]*[Quantity]*(1-[Discount])/100)*100) AS Subtotal, Count([Order Details].OrderID) AS [Count], Sum([UnitPrice]+[quantity]) AS total
FROM [Order Details]
GROUP BY [Order Details].OrderID, [Order Details].Quantity, [Order Details].UnitPrice;
Jaime E. Maccou
Reply With Quote
  #3 (permalink)  
Old December 30th, 2004, 02:19 AM
Registered User
 
Join Date: Dec 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Jaime,
I don't exacty know what you mean.

this is the data i have to work with:
XY Start and XY Dest are the start and end coordinates of a location in the warehouse.
I need to calculate the distanse for a terminal and therefor I need to extract
(see example) 35-34 and 155-157, 67-69 and 165-165 etc

Terminal X-Start Y-Start X-Dest Y-Dest
2 29 155 35 155
2 34 157 67 165
2 69 165 26 166
etc

My data does't have and can't have a unique recordnumber.
Paul

Reply With Quote
  #4 (permalink)  
Old December 30th, 2004, 06:01 AM
Authorized User
 
Join Date: Jul 2003
Location: Stockton on Tees, , United Kingdom.
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Your table needs some uniqueness as you cannot depend upon Access keeping the row order initially entered. Can't they be uniquely indexed on X-Start and Y-Start columns?


Cheers Ray
Reply With Quote
  #5 (permalink)  
Old December 30th, 2004, 06:56 AM
Friend of Wrox
 
Join Date: Nov 2003
Location: Lehigh Acres, FL, USA.
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

I asked GIS person about this. Here is a sample he shot at me.

With a little bit of Pythagoras, something like this might do the trick...

Code:
Private Sub cmdCalculateDistance_Click()
    Dim x1 As Double
    Dim x2 As Double
    Dim y1 As Double
    Dim y2 As Double
    Dim h As Double

    x1 = DLookup("[x-pos]", "Postal Codes", "[Postal Code] = " & cboStart)
    x2 = DLookup("[x-pos]", "Postal Codes", "[Postal Code] = " & cboEnd)
    y1 = DLookup("[y-pos]", "Postal Codes", "[Postal Code] = " & cboStart)
    y2 = DLookup("[y-pos]", "Postal Codes", "[Postal Code] = " & cboEnd)

    h = Sqr((x1 - x2) ^ 2 + (y1 - y2) ^ 2)

    MsgBox "The distance between " & cboStart & " and " & cboEnd & " is " & h & " kilometers."

End Sub
this is using a form with to combo box where you select the two coordinates and it will do the calculations

Jaime E. Maccou
Reply With Quote
  #6 (permalink)  
Old December 30th, 2004, 07:05 AM
Registered User
 
Join Date: Dec 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ray,

The data is from a query and in the underlaying table/query is also no uniqueness.
The data is daily updated from the main warehouse system and will be loaded into access.
I'm using maketable queries to create some tables. I don't know if there is an automated way
in this process to create an autonumber because I can't start doing it by 'hand'.

What may be the possibilities if I can make some uniquness in the query (Concatenate some fields maybe?),
because I got one extra field which i didn't mensioned in my example and that a field with a time element.

Paul



Reply With Quote
Reply


Thread Tools
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
store 2 records for future calculations gavmc Classic ASP Databases 0 November 16th, 2005 11:23 AM
store 2 records for future calculations gavmc Classic ASP Databases 0 November 16th, 2005 11:14 AM
Date Calculations Stu_morris40 Infopath 0 November 1st, 2005 10:53 AM
DateTime calculations sudarshan73 SQL Server 2000 1 March 15th, 2005 02:13 PM
Access Calculations bjackman Access 3 December 15th, 2003 08:44 PM



All times are GMT -4. The time now is 12:55 PM.


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