Looking Up Values in Access Tables.

Ok this is for my A2 Level project at school, i'm not that good a programmer (wouldn't even call myself begginner standard) but basically i'm trying to look up a value in an MS access table and reduce the value by a value in a feild on my user form when the save button is pressed.

Heres the "Basic idea", it's a drug prescribing system and basically the idea is it's checking the Drug name on the form (Form.Drug_Id) with drug names in the Drug table (Tbl_Drugs.Drug_ID) and it then reduces the amount remaining field in the drugs table, by the amount to be prescribed which is entered on the form (a basic stock system in other words):

Save_Click()
If Form.Drug_Id = Tbl_Drugs.Drug_ID Then Tbl_Drugs.Armount_Remaining = Tbl_Drugs.Armount_Remaining - Form.Amount

What i'm stuck on is how I write "Form.Drug_Id" so that Visual Basic understands it.

Anyway if anyone could help me, replying in as noobish friendly language as possible then it would be greatly appreciated.

PS I will obviousally make alterations to make sure the amount remaining dosent go below 0...

[1256 byte] By [Hilm] at [2007-12-28]
# 1

If you're trying to save this in Access (your datasource), then you'll need to add an update query to the TableAdapter that keeps track of your inventory.

UPDATE Table_Drugs
SET Table_Drugs.Count = Table_Drugs.Count - ?
WHERE Table_Drugs.Drug_ID = ?

You'll then pass two parameters into the query when you call the method that the tableadapter generates.

Me.TableAdapter_Drugs.UpdateInventory(Me.DataSet_Pharmacy.Table_Drugs, TextBoxAmount.Txt, Form1.Drug_ID)

Swade at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
Ok thanks alot =) i'll give that a go =)
Hilm at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...