inventory

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

is there an EASY way to add or subtrat parts used in a form from the total
amount of parts on hand in a table. I do not know code, and this is my first
database.
 
The 'easy' way is to have transaction records adding or subracting (stocking
& issuing) and then use a Totals query for display.

Another transaction records would be Inventory Adjustment.
 
As Einstein said about explaining the theory of general relativity, it can be
made as easy as possible but no more so. You need to put code in the
AfterUpdate event procedure of the form (or subform) in question. Hopefully
you won't have to amend the following code too much. Lets firstly assume:

1. The table is called Inventory and has a primary key column PartID and a
column QuantityOnhand, both number data types.

2. The form's underlying table has a foreign key column PartID which
references the primary key of Inventory.

3. The form's underlying table also has a column Quantity. Note that each
row in the form's underlying table should relate to one PartID only. For
multiple parts (per order say) you can use a subform embedded in a main form.
Do not under any circumstances have multiple columns in one row for multiple
parts per order.

4. Separate forms or subforms are used for parts received and parts
despatched. The code for each would differ only marginally, so I'll give
that for parts despatched first, requiring the Quantity to be subtracted from
the QuantityOnHand value in Inventory:

Dim cmd As ADODB.Command
Dim strSQL As String

Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText
cmd.CommandText = strSQL

' build SQL string to subtract quantity from QuantityOnHand
' for form's current part
strSQL = "UPDATE Inventory " & _
"SET QuantityOnHand = QuantityOnHand – " & _
Me.Quantity & " WHERE PartID = " & Me.PartID

' execute the command
cmd.CommandText = strSQL
cmd.Execute

For parts received, where you want to add the quantity to QunatityOnHand
merely requires the SQL string to be amended slightly to:

' build SQL string to add quantity to QuantityOnHand
' for form's current part
strSQL = "UPDATE Inventory " & _
"SET QuantityOnHand = QuantityOnHand + " & _
Me.Quantity & " WHERE PartID = " & Me.PartID

This does assume that for parts received ther is already a row in Inventory,
even if the QuantityOnHand is zero.

You could if you wished include some validation in the parts despatched code
to ensure that the quantity does not exceed the quantity on hand. If you do
this it would be better to use the form's BeforeUpdate event procedure as
this accepts a cancel argument which would prevent the record being saved if
the quantity cannot be met from inventory. The user could then reduce the
quantity and try again if necessary:

' execute the command if quantity on hand
' is sufficient
cmd.CommandText = strSQL
If DLookup("QuantityOnHand", "Inventory", "PartID = " & Me.PartID) >=
Me.Quantity Then
cmd.Execute
Else
MsgBox "Insufficient quantity on hand.", vbExclamation, "Warning"
Cancel = True
End If

BTW watch out for code breaking over more than one line in your news reader
when it should be a single line.

Ken Sheridan
Stafford, England
 
You rock man, thanks a million that worked fine. I will be getting myself a
book on visual basic code and start learning it. You have a great day.
Pam
 
You need Parts, Orders and Purchases tables. For your Orders form, include
both the Parts and Orders tables in a query abd base your form on this
query. From the Parts table you will have a Parts Inventory field and from
the Orders table, you will have a Quantity ordered. You need a little bit of
code in the form's AfterUpdate event something like:
Me!PartInventory = Me!PartInventory - Me!QuantityOrdered

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
(e-mail address removed)
 
Steve said:
You need Parts, Orders and Purchases tables. For your Orders form, include
both the Parts and Orders tables in a query abd base your form on this
query. From the Parts table you will have a Parts Inventory field and from
the Orders table, you will have a Quantity ordered. You need a little bit of
code in the form's AfterUpdate event something like:
Me!PartInventory = Me!PartInventory - Me!QuantityOrdered

--
This is to inform 'newbees' here about PCD' Steve:
http://home.tiscali.nl/arracom/whoissteve.html
Until now 3300+ pageloads, 2200+ first-time visitors (these figures are rapidly increasing)

To PCD' Steve: (this is also to inform those who do not understand...)
This is *not* about the sigline...(although you are far away from a 'resource' status).
But we will simply continue to hunt down *each and every* of your posts.

Why???
Because you are the ONLY person here who continues to advertise in the groups.

It is not relevant whether you advertised in *this* particular post or not...
==> We want you to know that these groups are *not* your private hunting grounds!

For those who don't like too see all these messages:
==> Simply killfile 'StopThisAdvertising'.
Newbees will still see this warning-message.

ArnoR
 
Back
Top