473,840 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

updating different tables from a form based on input

49 New Member
Feeling silly here - after creating a rather complex database that you guys helped with - this task seems simple... yet I am drawing a total blank.

I have a new project - building a database for a salon to keep up with customers and product sales.

Have a sales form which is truly only for inventory control, so
The form data is attached to a table named SalesTracker.
It has the following fields:


TransactionID <PrimaryKey>
SoldTo <uses combo box attached to Customers table, one column>
ItemName <uses combo box attached to Inventory table - 4 columns, ItemID, ItemName, ItemPrice & ItemsOnHand>
ItemsOnHand <pulls ItemsOnHand out of ItemName combo box column 3>
ItemPrice <pulls ItemPrice out of ItemName Combo box column 2>
QuantitySold <User input required>
SaleAmount <Calcuated using cmd button>

When the cmd button for calculate is pressed, I want to do the following:

sum the order using ItemPrice *QuantitySold (achieved this no problem)
update the ItemsOnHand field in the InventoryTable for the specific item by taking ItemsOnHand and subtracting QuantitySold value - got the math part... but drawing a blank when I go to update the Inventory Table for ItemID just sold.


Sorry, I am sure this is probably very simple... but its alluding me!

Sophie
Dec 27 '15 #1
8 1145
sooli
49 New Member
Ok, so I tried to do an update query - but am having trouble getting data from the form into the query. Using forms!SalesTrac ker!NewInventor y in the query but it keeps asking for that data, and yes the form is open when the query is run. I also tried to run an update query using the SalesTracker Table and the Inventory Table - but it is acting weird. If I have just opened the salestracker form, it works but if I go to another record and sell something else, it doesn't change anything. Then I noticed instead of changing just 1 record, it claims its changing 3 - but there are only 2 records in there?

here's the code:
Expand|Select|Wrap|Line Numbers
  1. UPDATE Inventory 
  2.    INNER JOIN SalesTracker 
  3.       ON Inventory.ItemID 
  4.          = SalesTracker.ItemID 
  5. SET Inventory.ItemsOnHand 
  6.     = SalesTracker.ItemsOnHand
  7. WHERE (((Inventory.ItemID)
  8.    =[SalesTracker].[ItemID]));
Dec 28 '15 #2
zmbd
5,501 Recognized Expert Moderator Expert
>> Sorry, cross posted with you...
>> Was called away, thought I had pressed submit and had not.
>> Will have to take a closer look at your new post however, I'll leave this as is as it might point in the right direction :)


sooli
There are several ways to do this; however, we don't have a full picture of your database design to be able to guide you in the right direction.

You can either open a record-set on the table and change the field holding the quantity

or

You could run an update-query using either the value you've pre-calculate or you could let the UAQ do the math for you. You can do this using either a stored query or via VBA.

If the CBO_ItemName has the primary key from Inventory table *([ItemID]?) then I would use something like
Expand|Select|Wrap|Line Numbers
  1. 'This is AIR CODE...
  2. zSQL = "UPDATE [tbl_inventroy]" & _
  3.    " SET  [tbl_inventroy]![ItemsOnHand]" & _
  4.         " = [ ItemsOnHand]-" & me.QuantitySold & _
  5.    " WHERE ((([tbl_inventroy]![ItemID])=" & _
  6.     Me.CBO_ItemName & "));"
  7. '
  8. zdb.Execute Query:=zSQL, Options:=dbFailOnError
>> Warning here> There are no user prompts or warning using the DAO Execute method!
>edit> In the WHERE clause, if [tbl_inventroy]![ItemID] is a string/text data, then the value returned by Me.CBO_ItemName will have to match those (which should be handled by the rowsource) and the returned value enclosed in quotes as:
Expand|Select|Wrap|Line Numbers
  1. " WHERE ((([tbl_inventroy]![ItemID])='" & _
  2.     Me.CBO_ItemName & "'));"
  3.  
Dec 28 '15 #3
zmbd
5,501 Recognized Expert Moderator Expert
If this is a stored query then you have to reference the form using the construct:
[Forms]![OpenFormNameHer e]![ControlNameHere]
to pull the form's value into the query.

Take a look at my previous post, the code I've inserted there would be ran from within your VBA for the command button's on_click event.
Dec 28 '15 #4
sooli
49 New Member
This is how I have it formatted and it's not working. Keep getting a popup like the field doesn't exist.

gonna try the code and see if i have better results.
Jan 2 '16 #5
zmbd
5,501 Recognized Expert Moderator Expert
1) Was the form open?
2) Double check the spelling for the control name and form as this is the most common issue.
3) if (2) doesn't solve the issue, then please post the script you are actually using, the post you've made doesn't show any reference to a form control.
Jan 2 '16 #6
NeoPa
32,584 Recognized Expert Moderator MVP
@Sophie.
Please pay close attention to what ZMBD is saying here. If you can master how best to communicate with others here - What information to include; What things to check for when things go wrong; How to proceed generally when things aren't working as expected; Etc. - you will have learned a lot more than simply how to fix this one problem. ZMBD's advice will lead you towards an approach that will stand you in very good stead going forwards. Precision and care related to what you do and how you communicate this to others are of supreme importance.
Jan 2 '16 #7
sooli
49 New Member
I got it! had a "." instead of "!"


Knew it was simple!!!! lol

Thanks for your help!
Jan 2 '16 #8
zmbd
5,501 Recognized Expert Moderator Expert
as always my pleasure to help... I love the easy fixes!

I've also revised my post#2 as I noticed a flaw in the aircode... just a minor thing and a caveat about string values in the WHERE clause of a SQL, just little things to keep in mind as you move forward with your projects/

B.O.L.
and Happy New Year!
Jan 2 '16 #9

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

Similar topics

4
2371
by: manning_news | last post by:
Using SQL2000. How do I format my select statement to choose one out of 24 different tables? Each table is slightly different and I was hoping I could use one select statement and format it on-the-fly instead of using 24 different ones. I had in mind using a case statement, something like this: select * from case when <input parameter> = 'something1' then tblSomething1 case when <input parameter> = 'something2' then tblSomething2...
3
11117
by: Jason | last post by:
I am trying to filter records in a primary form based on records in related tables. The data in the related tables is being displayed in the primary form through subforms. To be more specific, I have a primary form named TestResults, which is connected to data in a table named TestResults. There are basically two other tables that are related to the TestResults table (and the primary form) named Names-Normalized and SiteAddresses. The...
7
2108
by: Paolo | last post by:
I know I should not be doing this, but I find it very useful. I have a database in Access which stores data for a small company. Sometimes we need to add similar information to different tables. Currently I am already doing something similar by copying certain records into the same table. The only thing that changes is one field. Please look at the code: Dim MyDb As DAO.Database, MyRs As DAO.Recordset Dim strCode As String
10
15396
by: Marizel | last post by:
I'm not sure there's an easy solution to this, but thought I'd ask. I often find myself with a query which I'd like to reuse, but with a different datasource. These datasources generally have identical field names. The queries select a subset of the fields, so "Select *" is not really an option. Is there an easy way to change the source of a query, either in the design grid or SQL display? I suppose I could copy the SQL into WordPad...
0
1226
by: elmo | last post by:
Hi, I have a transaction table that I need to update from a from. The form should be able to display information from different tables. I have a Learner table with Learner information. I also have an type of qualification with various pieces of information about the qualification. What I want to do is to select the learner from a dropdown box and once selected, I need to populate various other fields on the form with information about...
0
888
by: stosh259 | last post by:
Hi everyone, Anyone have a generic procedure to updating different types of controls on a form. I have text boxes and switches (booleans). I would like to loop through all the controls and check if the values have changed since the form was loaded. I tried the following below for the text boxes: Private Sub CheckIfChanged(ByVal ctrls As Control.ControlCollection)
4
2368
by: Deus402 | last post by:
Here is my table design: tblEmployers EmployerID autonum (primary key) EmployerName text tblLocations LocationID autonum (primary key) EmployerID longint (foreign key) LocationAdress text
9
1663
by: Steve67 | last post by:
Need a little assistance with a VBA code for updating tables through a form. I have a form with two text boxes and a command button. One text box is named txtNewPartNumber and the other text box is named txtOldPartNumber. The idea is for the user to type in the old part number in the txtOldPartNumber box and type what the new part number is changing to into the txtNewPartNumber box then click on the command button to change the part numbers in 3...
5
1718
by: Usermatre Setepenre | last post by:
Hi, I have a problem whereby I need to delete a record from a form that is based on a Query that has two tables (1 to Many) relationship. I have the following sample of what I have tried: Private Sub Command63_Click() Dim CurrHospID As String Dim strSQL As String Dim intAnswer As Integer
2
2465
by: HumbleAprentice | last post by:
Hi All, I am new to PHP and mysql and would greatly appreciate your help. I am trying to learn PHP and mysql so I decided to create a project to help me do so. I created a registration form that post data to different tables in mysql database. My form contains a dropdown menu. I was able to post all the items from my form to the mathcourse table in mysql database but not from my dropdown menu. What I would like to achieve is that...
0
9864
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
10926
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10302
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7024
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5691
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4081
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3140
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.