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

Use a button to update a field in table based on single record in form?

Hello,

I have a form on which user enters information about what item he bought. If he chooses ID for this item which is already in warehouse, system must automatically add the amount to the one which is already in warehouse. But the problem is that in my code the system adds all the values depending on ID match but not the current record. I mean, if the items called "Box" with ID "12" and amount of 5 was bought on tuesday and the same item is in the other table called WAREHOUSE the system add 5 boxes and that ok, but the next day the same item with the same id was bought and the system still uses the amount of tuesdays and this days when it adds values in warehouse table.

I do believe that the main question is " How to connect the exact record on curent view of the form to table not all the records that exist under same ID?"
Apr 19 '10 #1

✓ answered by TheSmileyCoder

What you could do is to add to the forms AfterUpdate a statement like:
Expand|Select|Wrap|Line Numbers
  1. dim strSQL as string
  2. strSQL="UPDATE tbl_WareHouse SET lngQuant=lngQuant+ " & me.tb_Amount & " WHERE ID_Item=" & me.tb_IDItem
  3. docmd.setwarnings(false)
  4. docmd.runsql strSQL
  5. docmd.setwarnings(true)
  6.  
Here I have assumed a couple of things:
The amount of an item is stored in lngQuant in the table tbl_WareHouse
Your form has a textbox with the amount called tb_Amount
The ID of the item is in a textbox called tb_IDITEM.

Note that this only works if the warehouse allready contains a record for that item (Otherwise there is nothing to update). You can of course make a check in code whether there is a record with that ID, and act accordingly.

Let me/Us know if you need further assistance.

3 5830
TheSmileyCoder
2,322 Expert Mod 2GB
What you could do is to add to the forms AfterUpdate a statement like:
Expand|Select|Wrap|Line Numbers
  1. dim strSQL as string
  2. strSQL="UPDATE tbl_WareHouse SET lngQuant=lngQuant+ " & me.tb_Amount & " WHERE ID_Item=" & me.tb_IDItem
  3. docmd.setwarnings(false)
  4. docmd.runsql strSQL
  5. docmd.setwarnings(true)
  6.  
Here I have assumed a couple of things:
The amount of an item is stored in lngQuant in the table tbl_WareHouse
Your form has a textbox with the amount called tb_Amount
The ID of the item is in a textbox called tb_IDITEM.

Note that this only works if the warehouse allready contains a record for that item (Otherwise there is nothing to update). You can of course make a check in code whether there is a record with that ID, and act accordingly.

Let me/Us know if you need further assistance.
Apr 19 '10 #2
Thank you very much. It seems actually that your code is working perfectly now.
Apr 19 '10 #3
TheSmileyCoder
2,322 Expert Mod 2GB
Thats good to hear. Thank you for remembering to reply.
Welcome to Bytes.
Apr 19 '10 #4

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

Similar topics

0
by: EKL | last post by:
Hi, I'm making a sort of Customer and Orders database in MS Access 2003. My problem is that I wish to update the table "tblTransaction" based on changes made in the table "tblOrderDetails"....
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
4
by: Andy Proctor | last post by:
I hope there is an answer out there.... I have a simple database structured like this (non relevant tables and fields omitted) Members table memberID memberFname memberLname memberNokID
8
by: Lyn | last post by:
Hi, Can anyone tell me how the initial value displayed in Combo Box is determined when a form is opened? I am loading the dropdown from one field ("CategoryName") of a table, with "ORDER BY ". ...
3
by: jpr | last post by:
Hello, I know that this is not the rule but need some help. My datbase has three tables: MASTER TEMPLATES FORMS I have a form which is based on a table named MASTER. I have a primary key...
2
by: gordonjones | last post by:
I have users on different computers getting the error message "could not update;currently locked" when trying to leave identical fields after making a change on the same form but on different...
2
by: Brett | last post by:
My database has 2 tables: Table1 & Table2. If a field is not null on a record in table2, then the not null fields in table1 that correspond to the records in table1 needs to be updated to match the...
0
by: Access Programming only with macros, no code | last post by:
ERROR MESSAGE: Could not update; currently locked by another session on this machine. BACKGROUND I have the following objects: Table1 - HO (which has about 51,000+ records) Table2 -...
7
by: dscarbor | last post by:
I have a simple form with 4 fields, and a subform that retrieves records that are potential matches based on a query. The user will use the ID from the subform record and enter it into one of the...
13
by: Neil | last post by:
I'm running an update query in SQL 7 from QA, and it runs forever. Has been running for 20 minutes so far! The query is quite simple: update a single field in a table, based on a join with another...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.