Update Qty field in table based on Update Query - ms-access

I have 2 tables Inventory & Bom_Release joined by a Part_Num field the Inventory table contains a QTY field, the BOM_Release also has a qty_per field.
I have an aggregate query that sums the qty_per if the part_num is listed more than once.
I then have a query that looks at the Inventory table and the Aggregate query for a report.
All of that is working fine.
In the report I have qty and an unbound balance field, with
=[Inventory_Qty]-([Bom_Release_Qty]*[Forms!Kit_Release!WO_QTY_TXT]). Again the report works fine.
What I am struggling with is I can not figure out how to make an update query to do the same calculation as the report and actually update the qty in the Inventory table.
Very rusty, first DB I've done in almost 15 years. And even back then I was not very familiar with VBA. (I last used Access 97, Working with 365 now).
Thanks in advance.

Related

Totaling Records in MS Access

I have a query that returns the list of sales by customers, but I would like to know just the customer details and total value of sales. The only way I think of being able to do this is to create a second query based on the first one, remove the fields that cause unique records (e.g. description, goods) so I am only left with customer and sale value and then total/group that.
Is that the only way around or can this be done in one query.
Either this, or you can also copy your existing query, and do the grouping and summing in the copy.
But obviously you need two queries if you want both the full list and the totals query.
Edit: If you only need the totals, then edit the original query. Remove the columns you don't need, group by customer, sum the sale values.

Access query to find who didn't test over a range of dates

I am hoping someone can help me out with a query that may not be possible in Access.
I have a table with all employees and a query that shows everyone that has tested over an 18 month or so period and growing.
I am trying to figure out how I can do a query in access that will show what employees have not tested on individual dates within a range of dates. For example, if I create a query of the dates 10/1/17 – 10/14/17 then the result I am hoping for is that Jim did not test on 10/1 and 10/5 and Joe didn't test on 10/12.
It works great for a single date as it compares only the results from a single date query against the employee table and whoever is not in both did not test, but only for that date.
This is the SQL view of the single day “did not test” query:
SELECT ESD_EMP_BADGE.LAST_NAME, ESD_EMP_BADGE.FIRST_NAME, ESD_EMP_BADGE.EMPID, ESD_EMP_BADGE.DEPT
FROM ESD_EMP_BADGE LEFT JOIN Yesterday ON ESD_EMP_BADGE.[EMPID] = Yesterday.[EMPID]
WHERE (((ESD_EMP_BADGE.DEPT) Not Like "EXE") AND ((Yesterday.EMPID) Is Null));
For a range, I cannot do it the same way as the single date query because if that person tested at some time during the range of the query a single test in that range will make it seem like that person tested for all dates.
Is there a way that each date can be considered separately within a single query?
There is only one field that is guaranteed to be unique in the employee table that is also in the test records “EMPID”. There is no date field in the employee table.
I hope this is clear enough of an explanation. I think I might be reaching beyond what Access can do.
If I understand correctly what you are looking for - you will first need a dataset of all possible combinations of employees and test dates. This dataset can be generated with a query that includes employees and tests taken tables without a join clause. This is a Cartesian relationship of records - every record in each table joins with each record in the other table.
SELECT Employees.EmpID, EmpTests.TestDate FROM Employees, EmpTests;
Then join that query back to the testing table.
SELECT Query1.EmpID, Query1.TestDate, EmpTests.TestDate
FROM EmpTests RIGHT JOIN Query1 ON (EmpTests.TestDate = Query1.TestDate) AND (EmpTests.EmpID = Query1.EmpID)
WHERE (((Query1.TestDate) Between [start date] And [end date]) AND ((EmpTests.TestDate) Is Null));

Building a Access Report from a query

I have a query that has 3 columns: Payment Method, Count, Amount. When I try to create my report to bring in the data from the query, if a payment method has more than one in the count column it shows up as zero on my report for the count and the total. I am using the following in expression builder to bring in the data from the query:
for the number of the specific payments
=Sum(IIf([paymethod]="Discover",[Count],0))
for the total amount of all payments
=Sum(IIf([paymethod]="Discover",[Total],0))
The SQL behind the report
SELECT qryDailyDeposit.Count, qryDailyDeposit.Total, qryDailyDeposit.paymethod
FROM [qryTotal Deposit], qryDailyDeposit;
I guess your query with JOIN and Count(*) causes issues. Regardless, the following setup should guard you against unexpected results:
Payment Methods table:
Payments table:
Query:
Query results:
Now, just use the above query as datasource for your report:
Report datasource:
Report preview:
Make a new query to bind to the report:
SELECT paymethod, sum(amount) as [Amount], count(*) as [Total Payments] FROM yourTransactionTable GROUP BY paymethod ORDER BY paymethod
Once that's bound to your report you should be able to use a query wizard to build a quick report or design your own by dragging the bound fields over.
I'm guessing the reason you're getting 0 entry text boxes is that the report is going through each row returned by the query and on rows where the paymethod isn't "Discover", for example, it just outputs 0.

Difficult MS Access Query - how to combine them?

I am trying to build an access report based on data from multiple different tables within the database.
I have 3 columns which perform calculations, and I am wondering how to put this query together. All 3 columns deal with dates, but calculate them differently.
The first column retrieves the most recent date of action for a userid if the type of action is "B":
select pid, Max(date) as most_recent
from actions
where ref = 'B'
group by pid;
The second column performs a calculation based on 2 fields, one is a date and one is a number in months. I am unsure how to add these two fields so that the number is added to the date as a number of months.
what i have so far is:
select nummonths,Max(lastvisit) from users
the third column I need to select the first date thats in the future for each user (next appointment date), there will be dates before and after this date so its a little difficult:
select uid,date from visits
The code for the last 2 queries needs to be slightly modified, and I was wondering what the best approach would be to join these all together? A type of join?
If you need to build a report with data from the 3 queries, you will need related data to join them. In that case, please send the structure of the tables.
If you need to show 3 lists in one report, you can use subreports: create a new empty report. In design mode, you can add 3 subreports from the toolbox bar. To each of the subreport assign the record source property to the corresponding sql.
regards
I am unsure how to add these two fields so that the number is added to the date as a number of months.
Use the DateAdd() function:
SELECT DateAdd("m", 2, LastVisit) FROM ...
Results in a date two months from the LastVisit date.

adding mysql table values

I have a table in my database that holds numerical values collected from a user's input. How could I add those values together and display that number on the website, with the number updating every time a new number is inputed.
SELECT SUM(value) FROM table
Something like this? You should also look into GROUP BY.
EDIT:
It could be you're meaning that you have a value and you want to increment it by n. Then you can look at this example code.
UPDATE table SET value = value + n WHERE id = 123
Where n is the value you want to increment it by.
I would query a master table of IDs that has the running total of values.
Then, via any inserts into some alternate table that keeps each individual entry accounted for, there is a trigger that forces a SQL-Update to the master table... This way, you don't have to keep doing a web-based query that is always doing a GROUP BY for the results.
If this is a little confusing, think of an inventory system. You have one master item table of all possible inventory items. It has an "on hand" count. Then, as sales of an item are sold, the "on hand" count is reduced by however many are purchased. You are not going to each individual sales order and counting grouped by a given ID, you just go to thee master inventory item table and have that "on hand" count.