How to take fields value from another table? - ms-access

I have a table field in which I want to calculate the price of an order. In that table I have a field where you choose what dishes did the client order. And I need to get the prices of those exact dishes from another table and then sum them up. I want to calculate in field SASK and take prices from table VALGIARASTIS. So what should the formula be?
For example in field dish I choose Balandeliai,Bulviniai blynai, Cepelinai formula should take those names and get prices of it from table VALGIARASTIS and sum them up.
Here's a screenshot for you to understand.

The solution will not be a formula. It will be a VBA function that receive an array from the multi-value combo box, uses it to build a filter for the data in the VALGIARASTIS table, and uses an aggregate query to SUM() the price values.
For the first part, you can refer to these links:
http://allenbrowne.com/ser-50.html
http://support.microsoft.com/kb/135546
Once you have the means to filter a recordset, you can run an SQL query on the results using the SUM() function to get your total. You can run a DAO cursor through the recordset and get your total that way, but SQL is better.

Related

MS Access Control Source DLookUp

I haven't been able to make a DLookUp function work in an Access report. I can't figure out what I'm doing wrong.
The report is getting its dataset from a query called Aggregate Query. This query builds a dataset from 20 related tables using CustomerID as the primary key in one table and as a foreign key in the other 19. CustomerID is specified by an open Form with the desired customer's record displayed, including the CustomerID field.
This means Aggregate Query has several rows for one specific CustomerID. One field, Needs Notes, will have the same content on every row. What I'm having trouble with is getting only one of these rows displayed in the subreport, and subsequently on the parent report.
If there are six rows, say, in Aggregate Query, then the same Needs Notes field is repeated six times. I want it to appear only once in the subreport.
I couldn't choose only the first row from Aggregate Query. If this can be done that'd be great. I don't know.
So I created another query, Need-notes Only Query, which always gives me only one row every time. So far so good. Now I want the contents of the Needs Notes field to appear all by itself in the subreport. To do this I selected the text box and entered the following into the Control Source parameter:
=DLookUp("[Needs-notes Only Query]![Needs Notes]","Needs-notes Only Query")
No dice. I get six rows saying #Error.
Is there a way I can get just one row of the Needs Notes field into my report?
Split field and table names:
=DLookUp("[Needs Notes]","[Needs-notes Only Query]")

MS-ACCESS - Using returned value from DLookup as part of calculation

Please don't laugh. I'm sure this is something simple for all of you but as a novice, I'm in need of help.
I have an invoicing form which contains a subform. The subform allows users to select products and quantities.
For each product selected, users enter a quantity and the subtotal is automatically calculated. This part is fine.
My problem is, when I want to provide an overall total in the footer of the subform, I am just getting £0.00.
Here are the details:
Field one is called "Unit Price". This unit price is found using DLookUp. The formula is "=DLookUp("[Price]","[tblCashPrices]","[ProductID]=" & [Product] & "AND [SalesTypeID]=" & [Forms]![tblInvoice1]![SalesTypeID])"
This auto-populates and seems to be fine.
Field 2 is called "quantity" and is just a number field where users can enter an integer.
In the subform, I want to generate the overall total. I have tried "=sum([quantity] * [unit price])"
This is just returning £0.00.
I don't know what is going on because my subtotals for the products work but the overall total doesn't?
Please help
Aggregate functions must reference fields from table or query used as the form RecordSource, not a calculated control.
Better options than DLookup() on form to retrieve related data.
include the lookup table in the form RecordSource, join type: "Include all records from tblInvoices and only those from tblCashPrices that match."
multi-column combobox for the products, the price can be in a hidden column, then a textbox can reference the combobox column by index
Option 1 will allow the Sum() function to reference the Price field. Optionally, do the DLookup() calculation in a query and use that as the form RecordSource. Then the calculated field can be referenced in Sum() calc. Just be aware domain aggregate can be slow performer in query or textbox.
Another option is to create a field in table to store the price. Then use code (macro or VBA) to execute DLookup and save the retrieved value into that field.
Also, your DLookup() has syntax error in the WHERE argument. Need space each side of AND.
Record must be committed to table before the Sum() calc will update. Record is committed when: 1. close table/query/form; or 2. move to another record; or 3. run code to save.

how to populate column from the content of other columns after a row is inserted in the same table in mysql

I have a table traffic with 7 columns, namely toll_id, date1, shift, car_single, car_return, car_local and car_total.
How could I populate first 5 columns manually, and then store a value in column car_total, which will be the sum of car_single and car_return?
Here is the image of my table:
Just to add a 3rd and 4th ways of achieving the desired outcome:
If you have at least MySQL v5.7.6, you can use a generated column as car_total.
Alternatively, you can choose not to store car_total at all, but calculate this value on the fly while querying the table.
Having a column to store the results of the calculation is good if you regularly have search based on that field because you can use indexes to speed up the searches. Calculating the results on the fly may be better, if you just need to display the result of the calculation, but there is no need to filter on it.
There are two ways to do this:
Add the logic in the application itself, so that it calculates total before inserting the record. (Recommended)
Write an after insert trigger (http://dev.mysql.com/doc/refman/5.7/en/trigger-syntax.html) which calculates the count when record is inserted.

How to Multiply Two Fields in Microsoft Access

i Have created a query and i want to calculate the order price from the Orders table by the inventory quantity in the Inventory table. How this can be in the design view?
Create your query with the desired fields and the fields you need for the calculation :
Save the query.
Then, right click in an empty field and select Build...
The expression builder will open. All you have to do is supply your expression :
But if you really wantToLearnNewSkills, you should try writing SQL on your own, this isn't even that hard of a statement. Good luck.

SSRS 2008 - computing a sum while ignoring some columns

I swear this shouldn't be that hard, but it's been a real struggle.
I have a query that returns a site name, an event date, and the count of events. I use it in a very nice chart to show events by day.
I now want a Tablix to show the sum of those count of events by site. That is, ignore the date and just sum the counts.
I know I can write another query to accomplish this, but I'd rather minimize the number of queries in this report. How can I use the existing query to create the Tablix that I want?
in the tablix, create your group/groups that you want to sum by, then add the sum of the field you're summing. If you exlude the date in the groups then it'll just sum by whatever you group by.