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

Add Values in Table of Existing Data

Hi guys,

I have Form OrderLaptops and table laptops. I have fields in Laptops table like Description,Quantity,Location,Department,Part number etc....

and Description is a Primary Key so you cann't enter same data.

If I have Quantity(3) for Description(Dell),Location(Canada),Department(HR) and If I order to 2(Quantity) more Laptops of Dell(Description) in HR (department) of Canada(Location). so if i enter data in OrderLaptops form it should be automatically update data in table Laptops and there should be just one record like 5(quantity) and other fields are same.



So how can i do in access 2007?

Thank you very very much
Jun 15 '11 #1
4 5877
Adam Tippelt
137 100+
How does your form handle your 'input' to tell it that you are ordering two more? Once you've filled out the form, is there some sort of confirmation/update button?

If that's the case, you could put an update query in the _Click event of the confirmation button.

The query should be something along the lines of:

Expand|Select|Wrap|Line Numbers
  1. UPDATE TableLaptops SET TableLaptops.Quantity = TableLaptops.Quantity + Forms!OrderLaptops!QuantityField
  2. WHERE TableLaptops.Description = Forms!OrderLaptops!Description;
That works on the assumption that the quantity you put into the form is how much you're increasing the quantity by. If you instead want to declare the new TOTAL, then the query can easily be changed to something like this:

Expand|Select|Wrap|Line Numbers
  1. UPDATE TableLaptops SET TableLaptops.Quantity = Forms!OrderLaptops!QuantityField
  2. WHERE TableLaptops.Description = Forms!OrderLaptops!Description;
The where clause is important as it's used to identify that the record you update is only the record that you're looking at on the form, and not all the records.

If you want a more certain reply, you really could do with giving a bit more information about how the form actually functions (is the form bound to the table and you could just edit the records directly, or is it an unbound form that requires something like an update query)

Hope that helps.

Adam.
Jun 15 '11 #2
Actually I have Form OrderLaptops that have all data about table laptops means bound to laptops table and I have created ribbon in that there is one button "InsertData" if you click then it will open OrderLaptops form but it will not show all data it will just open new blank record and I do not have to confirmation button. you can not go or previous in that. So i am thinking if i got same data in table laptops then it should just change quantity.and if you open form OrderLaptops directly from elsewhere then it will show all data.

Thank you very very much
Jun 15 '11 #3
thanks dear,
i made button in the OrderLaptops form and in click event i write update query and its working exactlt that i want but
I want that if i write anything in form OrderLaptops it should add data in laptop table but if same record exist then it should update record.

Suppose I have Laptop 3(Quantity), HR(department),Canada(Location),HP(Description) then it should add new record in table and if I have that record exist in table then it should just add quantity so there should be quantity is 6 and every thing is same.

How can i do?
Thanks a Lot
Jun 15 '11 #4
Adam Tippelt
137 100+
You should be able to merge your AddData button with the Update button, so one button does all:

I don't know what code you've got behind your AddData button but I'm assuming it's along the lines of:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunCommand acCmdSaveRecord
  2. DoCmd.GoToRecord , , acNewRec
(or similar - something that contains a save new record function)

You could change this to include an if statement based on a Dlookup:

Expand|Select|Wrap|Line Numbers
  1. If IsNull(Dlookup("YourTableIDName", "TableLaptops", "[Quantity]=" & Me.Quantity & " AND " & "[Department]='" & Me.Department & "'" & " AND " & "[Location]=' & Me.Location & "'" & " AND " & "[Description]='" & Me.Description & "'")) then
  2.  
  3. DoCmd.RunCommand acCmdSaveRecord
  4. DoCmd.GoToRecord , , acNewRec
  5. (Or whatever your current AddData procedure is for saving new records)
  6.  
  7. Else
  8.  
  9. DoCmd.OpenQuery "YourUpdateQuery"
  10.  
  11. End If
(Take note of the additional single quotes round string based fields in the Dlookup criteria)

This code is written under the assumption that the input fields for Quantity, Department, Location and Description on the form are named the same as the table columns - if not, change the Me.<field> areas to the correct names.

You might also want to change your update query so that the WHERE clause checks that all fields are the same, instead of just the description:

Expand|Select|Wrap|Line Numbers
  1. UPDATE TableLaptops SET TableLaptops.Quantity = TableLaptops.Quantity + Forms!OrderLaptops!QuantityField
  2. WHERE (((TableLaptops.Quantity)=Forms!OrderLaptops!Quantity) AND ((TableLaptops.Department)=Forms!OrderLaptops!Department) AND ((TableLaptops.Location)=Forms!OrderLaptops!Location) AND ((TableLaptops.Description)=Forms!OrderLaptops!Description));
I think that should handle what you're after - that way when you click the AddData button, it'll decide if a record already exists for that combination of quantity/location etc, and just update it, or if it doesn't find an existing record, it'll add a new one.

Hope that helps.

Adam.
Jun 16 '11 #5

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

Similar topics

4
by: Hoang | last post by:
does anyone know how to dump the table structure and data from a mysql database? I am connected to the database externally so "SELECT * FROM database INTO OUTFILE file" doesn't work for me. ...
3
by: Raj | last post by:
Hi, I am trying to add some more information to the table which already has a lot a data (like 2-3000 records). The new information may be adding 2-3 new columns worth. Now my questions are:...
2
by: MikeY | last post by:
Hi everyone, Using C#, Windows forms. I am trying to learn how to modify existing data with in MSDE table/fields. If anyone could help me out with my code, I would appreciate it. My code is as...
13
by: nyt | last post by:
I have a problem of number and text field. I got the database file(mdb) that contains many combo boxes used and its list values are created by "value list" For eg field Field name= 'furniture'...
2
by: brob | last post by:
I am Access newbie looking for some guidance in putting together a query that can output a table of max values in a given column grouped by a couple of other columns. Here is an example of what I...
20
by: technocraze | last post by:
Hi guys & commnunity experts, Does anyone knw how to go about checking for existing data in an MS Acess table? I have tried out the following code using vb but doesnt seem to work that well? Can...
2
by: Gary42103 | last post by:
Hi I need Perl Script to do Data Parsing using existing data files. I have my existing data files in the following directory: Directory Name: workfs/ams Data File Names: 20070504.dat,...
0
by: cb123 | last post by:
Hello, Please bear with me I'm new to t-sql. I've had no luck trying to figure this out yet using sql code. I need to use an existing table (data dictionary) as input for creating a new table. ...
2
by: kostasgio | last post by:
Hello, this is my first post here, i hope i'll find this forum usefull. Although i did a search about my question, i didnt find what i need , because the question isnt exactly what it sounds. ...
1
by: Tracey Marshall | last post by:
The program is designed to collect and print data from user. It loops through the options. The user can input data, print the data to screen and then choose to input data again adding to 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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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,...
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...

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.