473,379 Members | 1,174 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,379 software developers and data experts.

Update Table Using Form and Query

Hello, I have a little problem, if anyone can help!
I have these 2 tables

Products:
ID
Product
Category
Current
Stock

Stock:
ID Product (Linked to Products Table)
Date
Type
Quantity

I would like to create a form Using the Stock Table that when completed would make a direct update in the "Current Stock" field on Products Table, based on the quantity of the product entered in the Form.

The products table is just a list of products from a particular location. In the Stock table we register inputs and outputs of these products, so when you take or enter a quantity of the product in the Stock table, it is necessary that the Current Stock value is updated in the products table.

If anyone can help on this I will be very grateful.
Thanks in advance!

This is really a simple stock table, we don't need much. The products we use are in only 2 categories "FOOD" or "Cleanliness and Hygiene" so there is no need for another table for that and this wont change.
The Type in the stock table is just to inform the types of moviments: "Purchase, Donate or Output". So we can know what kind of movement happend on the stock. Like in the stock tabler I will say that I received 10 packets of rice by donation, Or that we bought 10 packets of rice. When someone inputs that using the Stock form What I want is that the Rice register on Products table updates in the "Current Stock" Field. But I dont know how to do that, the actual mechanic to make an information Inserted on a form to automactly update another table other than the one on the form.
Feb 3 '17 #1

✓ answered by jforbes

People will tell you that you'll want to create this as a calculated field that is calculated when needed and not a static field stored in the database. That is pretty much true except in the case where there is too much data to effectively use a calculation.

So, probably your best option is to create a query based on your Products table and add the calculated field to it. You should be able to use the Query in place of your table in most cases and have your calculated field available. This means, you can change all your Forms that are based on Products table to the new Query and the Forms will continue to work.

Remove the Stock field from Products and then build a Query like the following and use it instead of the Products Table
Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2.   Products.ID
  3. , Products.Product
  4. , Parts.Category
  5. , Parts.Current
  6. , DSum("Quantity","Stock","ID=" & [ID]) AS Stock
  7. FROM Products
There are a lot of other ways to go about doing this, but the above method is simple, and I got the impression that you were attempting to keep things simple.

Another resource that you may want to look at is Allen Browne's article: Inventory Control: Quantity on Hand

Lastly, there are some reserved words in Access that if you use them, they can cause you trouble as Access expects those words to have a specific meaning. Date is one of these and it can throw Access off when it attempts to decipher a SQL string. I would recommend renaming that field to TransDate or something similar. You may also want to change Type.

1 1502
jforbes
1,107 Expert 1GB
People will tell you that you'll want to create this as a calculated field that is calculated when needed and not a static field stored in the database. That is pretty much true except in the case where there is too much data to effectively use a calculation.

So, probably your best option is to create a query based on your Products table and add the calculated field to it. You should be able to use the Query in place of your table in most cases and have your calculated field available. This means, you can change all your Forms that are based on Products table to the new Query and the Forms will continue to work.

Remove the Stock field from Products and then build a Query like the following and use it instead of the Products Table
Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2.   Products.ID
  3. , Products.Product
  4. , Parts.Category
  5. , Parts.Current
  6. , DSum("Quantity","Stock","ID=" & [ID]) AS Stock
  7. FROM Products
There are a lot of other ways to go about doing this, but the above method is simple, and I got the impression that you were attempting to keep things simple.

Another resource that you may want to look at is Allen Browne's article: Inventory Control: Quantity on Hand

Lastly, there are some reserved words in Access that if you use them, they can cause you trouble as Access expects those words to have a specific meaning. Date is one of these and it can throw Access off when it attempts to decipher a SQL string. I would recommend renaming that field to TransDate or something similar. You may also want to change Type.
Feb 3 '17 #2

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

Similar topics

3
by: GL | last post by:
Hi, Is there a way to add a field to an existing table using a query of some sort (without needing to manually add a field to the table). I know how to do it with a make table query, but I have...
2
by: jquest | last post by:
Hi Again; I am improving my database and have to overcome some original design mistakes. I have 3500 records in the table and I have had to insert new fields to track things I originally didn't...
3
by: ugo_lavoie | last post by:
HEy, this is normally pretty basic stuff but i dont know if i'm tired or what but right now i just can get it. Heres the problem... I have a form base on a table. 4 field : ID_Seller,...
5
by: SQL Learner | last post by:
Hi Alex (Kuznetsov) and All, This is to follow up with my last post, "Link two tables using partial word match". How can I UPDATE table using partial word match? How can I write a SQL statement...
2
by: Margie | last post by:
Hello again After getting great help perfecting my little Access 2007 movies database, I've stumbled upon an inconvenience. In my opinion it seems basic, but still I'm not able to solve it. As an...
1
by: adithi | last post by:
My Table Structure is: Table A Table B Table C colA -PK Col B-PK Col C-PK Col B-FK ...
11
by: flametail | last post by:
I have a php script that shows all the data in a table. I want it to have check boxes next to each line of this data that it puts out, so I can check the boxes next to certain entries, and when I...
2
by: Axcelia | last post by:
i'm using sql 2008 and .net 2008.... i need to insert system time in the table by using sql query... pls help me
5
by: pravinalone888 | last post by:
Hi, I am stuck-up in a situation and would required a suggestions ... I have a table called "Emp" (around 160000 records) having fields (EmpName, Designation). No other fields in table. I...
1
by: Shawn29316 | last post by:
Hi, I have a query that says: Select Distinct Bids.EmpID, Bids.PosID, ! AS ReqNum From Bids; The query works fine until I try to use it to populate a table, then the ReqNum field is always...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.