473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Storing Calculations

111 100+
Ok so i know you shouldn't store calculations in a table, but what if i need to? i have calculations on one form, and i want to be able to show the value of that calculation on a different form based off a totally different table.

how would i go about doing that?
Oct 18 '07 #1
18 1638
NeoPa
32,556 Expert Mod 16PB
Base the second form on a query that includes input from the tableS you need.
I can't help any more for the moment I'm afraid, as your question is almost completely devoid of information I could use to help you :(
Oct 18 '07 #2
nico5038
3,080 Expert 2GB
Another option is to use a Dlookup() function, that will allow a calculation like:
Expand|Select|Wrap|Line Numbers
  1. dlookup("field1 * field2","your table","ID = " & [ID])
  2.  
Nic;o)
Oct 19 '07 #3
Neekos
111 100+
The calculation i need to look up is a long one. Would this still work in the DLookup?
Expand|Select|Wrap|Line Numbers
  1. =DLookup("Sum(([Grats]+[Insurance]+[Cruise Rate]+[Port Charges]+[Taxes]+[Air]+[Other])+([Grats2]+[Insurance2]+[Cruise Rate2]+[Port Charges2]+[Taxes2]+[Air2]+[Other2])+([Grats3]+[Insurance3]+[Cruise Rate3]+[Port Charges3]+[Taxes3]+[Air3]+[Other3])+([Grats4]+[Insurance4]+[Cruise Rate4]+[Port Charges4]+[Taxes4]+[Air4]+[Other4])+([Grats5]+[Insurance5]+[Cruise Rate5]+[Port Charges5]+[Taxes5]+[Air5]+[Other5]))", "tblManifest", "GroupNumber = '" & Me![GroupNumber] & "'")
i tried using it on the OnOpen event of the form like so:

Forms![frmGroupPayments]![GrossAmt] = DLookup(....same as above....)

but get an object required error.
Oct 22 '07 #4
NeoPa
32,556 Expert Mod 16PB
As a full member now, you should know that we expect your code to be posted in [code] tags (See How to Ask a Question).
This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.
Please use the tags in future.

ADMIN.
Oct 22 '07 #5
NeoPa
32,556 Expert Mod 16PB
The calculation i need to look up is a long one. Would this still work in the DLookup?
Expand|Select|Wrap|Line Numbers
  1. =DLookup("Sum(([Grats]+[Insurance]+[Cruise Rate]+[Port Charges]+[Taxes]+[Air]+[Other])+([Grats2]+[Insurance2]+[Cruise Rate2]+[Port Charges2]+[Taxes2]+[Air2]+[Other2])+([Grats3]+[Insurance3]+[Cruise Rate3]+[Port Charges3]+[Taxes3]+[Air3]+[Other3])+([Grats4]+[Insurance4]+[Cruise Rate4]+[Port Charges4]+[Taxes4]+[Air4]+[Other4])+([Grats5]+[Insurance5]+[Cruise Rate5]+[Port Charges5]+[Taxes5]+[Air5]+[Other5]))", "tblManifest", "GroupNumber = '" & Me![GroupNumber] & "'")
i tried using it on the OnOpen event of the form like so:

Forms![frmGroupPayments]![GrossAmt] = DLookup(....same as above....)

but get an object required error.
That should work if there are no mistakes in the code (We can't tell as you're still posting the minimum you can get away with information-wise). This would be easier to do and more straightforward with a query though (as well as better optimised but that won't be a major issue I wouldn't think). If you don't share very much info we have to work hard to guess what you're about. My best guess is that the query would suit you better BUT the DLookup should work if it's done properly. If you post the code you've used and show which line the error occurrs on (the DLookup() in this case I expect) then we may be able to be more help.
Oct 22 '07 #6
nico5038
3,080 Expert 2GB
The calculation i need to look up is a long one. Would this still work in the DLookup?
Expand|Select|Wrap|Line Numbers
  1. =DLookup("Sum(([Grats]+[Insurance]+[Cruise Rate]+[Port Charges]+[Taxes]+[Air]+[Other])+([Grats2]+[Insurance2]+[Cruise Rate2]+[Port Charges2]+[Taxes2]+[Air2]+[Other2])+([Grats3]+[Insurance3]+[Cruise Rate3]+[Port Charges3]+[Taxes3]+[Air3]+[Other3])+([Grats4]+[Insurance4]+[Cruise Rate4]+[Port Charges4]+[Taxes4]+[Air4]+[Other4])+([Grats5]+[Insurance5]+[Cruise Rate5]+[Port Charges5]+[Taxes5]+[Air5]+[Other5]))", "tblManifest", "GroupNumber = '" & Me![GroupNumber] & "'")
i tried using it on the OnOpen event of the form like so:

Forms![frmGroupPayments]![GrossAmt] = DLookup(....same as above....)

but get an object required error.
Best to put into the Controlsource of [GrossAmt]:
Expand|Select|Wrap|Line Numbers
  1. =Dlookup("...","...","...")
  2.  
I also suspect the SUM() not to work as it requires a groupby function.
When the summing is needed for all rows to one GroupNumber, then first define a GroupBy query to perform the summing per field and use only the "+" for summing these fields like:
Expand|Select|Wrap|Line Numbers
  1. ([Grats]+[Insurance]+[Cruise Rate]+...
  2.  
Getting the idea ?

Nic;o)
Oct 22 '07 #7
Neekos
111 100+
i appologize for not using the code tags, i simply forgot.

As for the DLookup, you are right about the Sum function not working. So instead a built a query. When i run the query by itself, it is returning the correct value for the Sum of all of the values. However, when i add the query to the control source (i only added the field which has the totals) and then open my form - it is displaying a completly different value, and is also changing other calculations on the form that have nothing to do with the query.

What info would you need so that i can help you help me?
Oct 22 '07 #8
Neekos
111 100+
Also i forgot to mention that when i added the query to the control source, it is adding the same record multiple times on my form - which is the reason why its changing the value of the calculations.
Oct 22 '07 #9
Neekos
111 100+
My control source looks like this:

Expand|Select|Wrap|Line Numbers
  1. SELECT tblGroupPayments.*, qryGrossAmt.Expr1 FROM tblGroupPayments, qryGrossAmt; 
Oct 22 '07 #10
nico5038
3,080 Expert 2GB
Just keep the controlsource of the form as you had.

The query needs to be used in the DLOOKUP() function as the second parameter like:
Expand|Select|Wrap|Line Numbers
  1. =Dlookup("a+b+c....","qryGroupBy","...")
  2.  
Nic;o)
Oct 22 '07 #11
FishVal
2,653 Expert 2GB
Hi, Neekos.

[tblManifest] by no means looks like a normalized table. I hope you quite aware of the fact that its the first (and maybe the last) reason of you present difficulties and future problems.

Plz, post [tblManifest] metadata. Here is an example of how to post table MetaData :
Table Name=tblStudent
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. StudentID; AutoNumber; PK
  3. Family; String; FK
  4. Name; String
  5. University; String; FK
  6. Mark; Numeric
  7. LastAttendance; Date/Time
Also take a look on Database Normalisation and Table structures tutorial.

Regards,
Fish
Oct 22 '07 #12
Neekos
111 100+
Just keep the controlsource of the form as you had.

The query needs to be used in the DLOOKUP() function as the second parameter like:
Expand|Select|Wrap|Line Numbers
  1. =Dlookup("a+b+c....","qryGroupBy","...")
  2.  
Nic;o)

Ok i put the form's control source back to the orginal table.

And i put the control source of the txtbox to this:

Expand|Select|Wrap|Line Numbers
  1. = DLookup("Expr1", "qryGrossAmt", "GroupNumber = '" & Me!GroupNumber & "'")
but i get a #Name error.


Also, i realize my table isnt very normalized at all, i'm still very new to Access and this was the only way i could get it to display the info as i needed. You see, the purpose of my db is to display a manifest for a Group cruise booking. Every group will have multiple cabins, and each cabin can have up to 5 passengers. The only way i could figure out how to display the info as needed was to make each cabin its own record, and have a field for each passenger - including all of the charges associated with each passenger. There may have been an easier way of doing it, but im too far along to have to start over.
Oct 22 '07 #13
Neekos
111 100+
ok i figured out that it doesnt like the Me!GroupNumber, because if i change that to the actual group number, it works.

what can i change it to so that it looks up the value associated with the current group number?
Oct 22 '07 #14
nico5038
3,080 Expert 2GB
Best to start reading the link FishVal provided you with.
Having the wrong table structure causes trouble like this and makes the database much harder to expand in the future.

I spend in general as much time (or even more) on the table design as on the creation of the forms and reports.

The solution for your problem is to change in the WHERE section of the DLOOKUP function the Me!GroupNumber into [GroupNumber].

Nic;o)
Oct 22 '07 #15
Neekos
111 100+
That worked, thank you for all your help.

And i will read up on the table structure so that i dont run into further problems down the line! Thank you both!
Oct 22 '07 #16
nico5038
3,080 Expert 2GB
Glad we could help, and best to start changing the design of your tables now :-)

When you define the requirements, be sure we can help you.

Nic;o)
Oct 22 '07 #17
NeoPa
32,556 Expert Mod 16PB
Neekos.

I'm sure you're new to this so it's understandable that you think that way, but you're making your own problems here.
Also, as you move away from the standard way of doing things you move away from where we can help you.
Most of the Experts here understand WHY normalised databases are better. In simple terms, it's because it works better and it makes it easier for you, the designer, to understand what's going on.
Clearly this is your choice, but when you come to look for who's responsible for it all getting horribly complicated you know where to start right?
Moving on.
DLookup() is only one of a whole group of Domain Aggregate functions available to you. Personally I would not use this method in your situation, but you can use DSum() to get the sum of the group of records that you're interested in. If you're only adding different fields from a single record then the + operator is sufficient.
Oct 22 '07 #18
NeoPa
32,556 Expert Mod 16PB
It seems you guys were posting faster than I could keep up :D
If you're happy, then I'm happy.
Oct 22 '07 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Steven | last post by:
Hi there, I am wanting to store price data as n.nn format, so if the user enters "1" the data that gets stored is "1.00" Is there a way to do this. Cheers Steven
0
by: John Hicks | last post by:
Is there an accepted best practice on whether to store decimal currency amounts (e.g. dollars and cents) in MySQL decimal column types? Certainly, the most straightforward way is to use decimal...
7
by: Arnold | last post by:
I need to read a binary file and store it into a buffer in memory (system has large amount of RAM, 2GB+) then pass it to a function. The function accepts input as 32 bit unsigned longs (DWORD). I...
11
by: lduperval | last post by:
Hi, I`m trying to do date calculations in three types of time zones: local, GMT and specified. The issue I am facing is that I need to be able to specify a date in the proper time zone, and I`m...
2
by: JP SIngh | last post by:
Hi All I am writing an ASP application that deals with the TV tapes and two of the fields is what I am having issues with I need to store the duration of the program i.e. DURATION field only...
8
by: TORQUE | last post by:
Hi, I am having some trouble with recording a field on a form into my Table after formatting it to calculate several fields on the form. If i just put the amount in the field and have it linked...
7
by: fauxanadu | last post by:
Is it possible to store dates before 01/01/0100 A.D. (such as for as database storing world events would require) using MS Access? Verbose Explination I need to be able to store dates before...
1
by: djcapslock | last post by:
Hi, I am producing a database which does some statistical calculations, so far I have been storing results of upper quatiles and lower quartiles of results as the calculations seem to take a...
9
Catalyst159
by: Catalyst159 | last post by:
I have a form which is used to calculate residential Floor Area Ratio (FAR). The form is structured into seven parts as follows: Part A: Maximum FAR and Floor Area: Part B: Gross Floor Area of...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.