473,406 Members | 2,378 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,406 software developers and data experts.

Adding values in a table

20
Hi,

Im trying to create a stock control system. But the stock is in two different places. What this means is the table must contain stock values from each place and then a overall total must be given. But im not sure how to be able to add the two up and display it in the same table.

Can anyone help me please?
Jun 20 '07 #1
5 1351
kepston
97 Expert
It is not recommended to store a calculated value within the same record as the fields used in the calculation (unless a different value from the calculation is not wrong).
It is better to store the actual values and use a Query to display calculations.

Part, Location, Qty
M6 Screw, A1, 2000
M8 Screw, A2, 1000
M6 Screw, A3, 500

Expand|Select|Wrap|Line Numbers
  1. select Part, Sum(Qty) AS Total
  2. from tblStock
  3. group by Part;
would give

Part, Total
M6 Screw, 2500
M8 Screw, 1000
Jun 20 '07 #2
aman909
20
That is a good way of doing but im not sure if it will work for me. What i have is:

Colour Stock1 Stock2 Total Stock
Red 50 100
Blue 100 200

What i need is for the total stock be added from stock1 and stock2. Do you know a way to be able to this.
Jun 20 '07 #3
kepston
97 Expert
That is a good way of doing but im not sure if it will work for me. What i have is:

Colour Stock1 Stock2 Total Stock
Red 50 100
Blue 100 200

What i need is for the total stock be added from stock1 and stock2. Do you know a way to be able to this.
If this is a table, then I would recommend you create a query to display Total Stock.
Expand|Select|Wrap|Line Numbers
  1. select Colour, Stock1, Stock2, Stock1+Stock2 as [Total Stock]
  2. from tblStock;
Or if you want to display it in a form, create an unbound text box with Data =Stock1+Stock2

If you must store [Total Stock] as a field, you should create a form with an AfterUpdate event on each of Stock1 and Stock2 to modify [Total Stock] when either changes. But be aware that if either update fails to occur, you could end up with a value in [Total Stock] that is not the sum of Stock1 and Stock2. Equally, if any of the three values are changed when viewing the table, your rules will not be enforced, again giving you inaccurate stock levels.
Jun 20 '07 #4
aman909
20
I need to be able to store that total stock in a field. how would i create a update form for that
Jun 21 '07 #5
kepston
97 Expert
I need to be able to store that total stock in a field. how would i create a update form for that
In the properties window of your text boxes, on the form, is a tab marked Event.
in AfterUpdate choose [Event Procedure] and click on the builder button [...].
A Visual Basic window will open showing something like
Expand|Select|Wrap|Line Numbers
  1. Private Sub Stock1_AfterUpdate()
  2.  
  3. End Sub
In the gap between Private Sub ... and End Sub you must write your code to manipulate the fields (in the example above that would be line 2)
For each of Stock1 and Stock2 you will need something like
Expand|Select|Wrap|Line Numbers
  1. Me.Total_stock = Me.Stock1 + Me.Stock2
I also recommend that on your form you Lock the field [Total Stock] so that it can't be changed by the user.
Jun 22 '07 #6

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

Similar topics

10
by: Sunny K | last post by:
Hi guys, I have a field in my DB called EventDate as a DateTime field, therefore it holds both the date and time together like this: '2004-10-14 08:42:57.000'. I need to add together all the...
1
by: HolaGoogle | last post by:
Hi all, Please help me with the following..it's realy urgent and i tried everything i could and i can't get it work properly!! Thanks in advance. Here's what i'm trying to accomplish: in my...
5
by: Paul | last post by:
Hi I have a table that currently has 466 columns and about 700,000 records. Adding a new DEFAULT column to this table takes a long time. It it a lot faster to recreate the table with the new...
2
by: Viorel | last post by:
Adding new row with default values. In order to insert programmatically a new row into a database table, without direct "INSERT INTO" SQL statement, I use the well-known DataTable.NewRow,...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
5
by: Aaron Ackerman | last post by:
I have a bound combobox the appears on a cell within the column of my bound grid when the user clicks on a cell n(In my vb.net WinForm app). I am trying to allow the adding of an item to that bound...
10
by: Trevor | last post by:
Hey, I am trying to do this tutorial on the microsoft site : http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dndotnet/html/usingadonet.asp I can get everything to work up to...
6
by: Rudy | last post by:
Hi all, I know this is easy, just can't seem to get it. I have a windows form, and a text box, with a value already in it. I need to add that value to a table. It's just one value, so the entire...
7
by: Miro | last post by:
Im a VB Newbie so I hope I'm going about this in the right direction. I have a simple DB that has 1 Table called DBVersion and in that table the column is CurVersion ( String ) Im trying to...
3
by: john | last post by:
In my form (table A) I have subform (table B (only 2 fieds: ID and App_name) where table A -Table B are linked 1XM. To be able to add a record in the subform I want to use a lookup form since the...
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: 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: 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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.