Code for subtracting inventory

J

Josh

Does anyone know how I can make Access (SQL) subtract
from an inventory supply. If I enter an order for 2
items, how can it automatically subtract 2 from the
inventory? Thanks.
 
A

Ayelet

Hi,
Try this:
'Code Start
Dim DB As DAO.Database
Dim rsOrder, rsItems As DAO.Recordset

Set DB = CurrentDB
Set rsOrder = DB.OpenRecordset ("Select * From
OrderDetailsTbl Where [OrderID] = " & Me![OrderID])
Set rsItems = DB.OpenRecordset("ItemsTbl")

Do Until rsOrder.EOF
rsItems.FindFirst("[ItemID] = " & rsOrder![ItemID]
If rsItems.NoMatch Then
MsgBox "Couldn't find item - skipping"
Else
rsItems.Edit
rsItems![Amount] = rsItems![Amount] - rsOrder!
[Quantity]
rsItems.Update
End If
rsOrder.MoveNext
Loop
'Code Ends

You could probably do this with an Update query as well,
but you should Never fear a little programming!
Good Luck
Ayelet
 
D

Dirk Goldgar

Josh said:
Does anyone know how I can make Access (SQL) subtract
from an inventory supply. If I enter an order for 2
items, how can it automatically subtract 2 from the
inventory? Thanks.

Along the lines of

CurrentDb.Execute _
"UPDATE Inventory " & _
"SET QtyOnHand = QtyOnHand - " & Me!QtyOrdered & _
" WHERE ItemID=" & Me!ItemOrdered,
dbFailOnError

That's assuming you've performed all necessary checks to ensure that you
have in fact got the required quantity of this particular item in the
inventory.
 
G

Guest

Thank you both very much, My inventory looks okay, I'm
going to try the coding.

-Josh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top