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

updating different tables from a form based on input

49
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

✓ answered by zmbd

If this is a stored query then you have to reference the form using the construct:
[Forms]![OpenFormNameHere]![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.

8 1128
sooli
49
Ok, so I tried to do an update query - but am having trouble getting data from the form into the query. Using forms!SalesTracker!NewInventory 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 Expert Mod 4TB
>> 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 Expert Mod 4TB
If this is a stored query then you have to reference the form using the construct:
[Forms]![OpenFormNameHere]![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
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 Expert Mod 4TB
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,556 Expert Mod 16PB
@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
I got it! had a "." instead of "!"


Knew it was simple!!!! lol

Thanks for your help!
Jan 2 '16 #8
zmbd
5,501 Expert Mod 4TB
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
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...
3
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...
7
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....
10
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...
0
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...
0
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...
4
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
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...
5
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:...
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
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
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,...

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.