473,386 Members | 1,741 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.

How to assign a selected value in a combo box to a table field.

I'm designing a small stock control system with 2 tables: Item table composed of: itemid, itemname and quantityonhand. Transaction table composed of: TransID, itemid, TranCode (IN, Out), quantity and date of transaction. I designed a form consisting mainly of a combobox based on the Item table. The combo box displays the ItemName of all items in the table and the ItemID which is hidden. then there is a textbox where a user enters the Quantity and another for the date and a third for the Trans code. The system should work like this: User selects an item from the combobox, enters quantity, date and trans code. A record is added to the transaction table, and the corresponding record in the Item table is updated by either adding to or subtracting from the quantityonhand depending on the Trans code.
My problem is I failed to write the correct code for linking the selected item from the combobox to the corresponding record in the Item table.
Aug 29 '10 #1
3 2292
liimra
119 100+
I assume that you already created One-to-Many relationship between the two tables based on ItemID.
(ItemID in ItemTable is Unique but can be used many times in the Transaction Table as you will sell and buy the same item many times).

If the above is true, you have to create a form based on the Transaction table and not on the Item Table. All fields contained in the transaction table should be there. The query for the combobox you create should contain two columns: ItemName which will be displayed to be chosen and ItemID which will be hidden. On the AfterUpdate Event, Embed a Macro with SetValue action so it sets the value for the ID field (Transaction Table). This can be done via VB but in Macro case: the Item = ItemID & The Expression would be = [ComboBoxName].[column](2).

The above should solve the linking problem.

For entering the calculation (+/-) in the Item Field, I am afraid this is not possible. Why should you save calculations, when you are able to display them at any time using Queries,Forms, & Reports. But it doesn't stop here. In order to have the running quantity (Balance on Hand), you have two solutions of which I know. The first is to have the Quantity in the Transaction table recorded as (+) when you purchase and (-) when you sell; and then you use DSum. The second is to have two transaction tables, one for sales & one for purchases and this what I would recommend. In this case, you use DSum(Purchases where ID is ..) - DSum(Sales where ID is...).


Hope this helps,
Regards,
Ali
Aug 29 '10 #2
Thank you Mr. Ali, will try it.
Aug 29 '10 #3
liimra
119 100+
Did you work it out?

Regards,
Ali
Sep 16 '10 #4

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

Similar topics

2
by: Sajid | last post by:
Hello, I have the following case where I want to assign a value to a column in a row. But it gives me an error that "Property Item is readonly": DataAdapter.Fill(DataTable1) Dim clone as...
0
by: gary b | last post by:
My forehead is sore from beating it against the wall. Can anyone help? I've started drinking again because of this problem! Setup: ContestantTbl = table ('one' side) HorseTbl = table ...
2
by: CSDunn | last post by:
Hello, I have a field called 'TestGrade'in a subform called 'frmSelectByTestSub'that I need to assign a default value to, and the value needs to be an integer value that is exactly the same as the...
1
by: K. Davis | last post by:
I need to increment the maximum value of a field of a table by 1 when a form opens a blank record. (e.g. =max(!![trip_number}) so the logic and references are working at the form level. I've...
1
by: MLH | last post by:
Can someone tell me what I'm doing wrong in this query? UPDATE tblEventsSituationsIncidents SET tblEventsSituationsIncidents.ES01 = +1; I'm trying to update the value in table field and am...
8
by: Woody Splawn | last post by:
Lets say I have a winform that is populated with a dataset. The dataset and data table may have several rows in it. Lets say I am looking at the winform and I want to assign a value to a certain...
1
by: davidbennett | last post by:
Hello, I am new to MS Access. I have created a series of forms that users access to perform data entry. I now need to build in reporting functionality. I would like to create a form that has a...
2
by: Lars Erik Nes | last post by:
Hi I can't get this to work. I have a CustomerForm which display data from several tables in datagridviews. In another form (opened from CustomerForm), called NewCallForm, i have a listview...
3
by: Sheldon | last post by:
How can this be done and what is the syntax? Thanks, Sheldon Potolsky
1
by: dmj07 | last post by:
Hi all, I was wondering of an easy way to set the selected value of a drop down list by using a value retrieved from the database. Here is my code: SqlCommand cmdUser = new...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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,...

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.