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

Updating table using a form?

Hi Everybody, I am hoping somebody will be able to help me with this..

I have a simple table called Product - This table has 5 fields:
1. Design_Code (this is the primary key)
2. Original_Qty
3. Qty_Sold
4. Qty_Available
5. Price


I also have a Form which has a ListBox that gets its values from the Design_Code field.

I also have a CommandButton.

What I am trying to do is...every time the CommandButton is pressed, I want one unit to be deducted from the Qty_Available field for the value which is selected in the ListBox. And one Unit to be added to the Qty_Sold field.

Can someone please tell me the best way to do this?

Thanks in advance for your help.

Cheers
Aug 28 '07 #1
1 1298
Scott Price
1,384 Expert 1GB
Hi Everybody, I am hoping somebody will be able to help me with this..

I have a simple table called Product - This table has 5 fields:
1. Design_Code (this is the primary key)
2. Original_Qty
3. Qty_Sold
4. Qty_Available
5. Price


I also have a Form which has a ListBox that gets its values from the Design_Code field.

I also have a CommandButton.

What I am trying to do is...every time the CommandButton is pressed, I want one unit to be deducted from the Qty_Available field for the value which is selected in the ListBox. And one Unit to be added to the Qty_Sold field.

Can someone please tell me the best way to do this?

Thanks in advance for your help.

Cheers
A fairly simple UPDATE query should do the trick. You will call this with your command button's OnClick event.

Expand|Select|Wrap|Line Numbers
  1. Dim MySQL
  2. 'Test to make sure something really is selected in the ListBox
  3. If Not IsNull(Me![ListBoxName]) Then 
  4. MySQL = "UPDATE Products SET [Qty_Available] = ([Qty_Available] - 1),  Qty_Sold] = ([Qty_Sold] + 1) WHERE [Design_Code] =" & Me![ListBoxName] & ";"
  5. DoCmd.RunSQL MySQL
  6. End If
You'll likely want to add some error handling, and make sure to change the Names inside []'s to reflect the actual names in your database.

Regards,
Scott
Sep 2 '07 #2

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

Similar topics

3
by: | last post by:
Hello, Sorry to ask what is probably a simple answer, but I am having problems updating a table/database from a PHP/ PHTML file. I can Read From the Table, I can Insert into Table/Database, But...
11
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? ...
2
by: Ray Holtz | last post by:
I have a form that shows a single record based on a query criteria. When I click a button it is set to use an append query to copy that record to a separate table, then deletes the record from the...
1
by: chrisc | last post by:
Hello, Im using redemption in a database created in ms access. At the moment emails are generated depending on various actions within a database. To give an example: Public Const...
10
by: jaYPee | last post by:
does anyone experienced slowness when updating a dataset using AcceptChanges? when calling this code it takes many seconds to update the database SqlDataAdapter1.Update(DsStudentCourse1)...
33
by: bill | last post by:
In an application I am writing the user can define a series of steps to be followed. I save them in a sql database using the field "order" (a smallint) as the primary key. (there are in the range...
6
by: Dave | last post by:
I want to put the information that the user selects in my combo boxes into a subform that lies on the same form as the combo boxes. Thanks for your help already, Dave
3
by: Spoogledrummer | last post by:
Hi it's me again, still working on the sam 5 minute problem so feeling kind of thick now. I've dumped the idea of using a textarea for now and am using a textbox instead but am struggling when it...
5
stepterr
by: stepterr | last post by:
I have a form that is built based on a query. Everything is working except when I submit the form the radio buttons are only updating the first row in my database. dcategory and dthumbnail are two...
2
by: =?Utf-8?B?VmFuZXNzYQ==?= | last post by:
Hi All! I am with a situation where I am not getting the right updating to the form's fields. The situation is the following one: I have one combobox and one textbox. I am using the...
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
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...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.