Allen,
Thanks for getting back to me. I made changes in the code
to reflect the feild s that I have inmy tables very
carefully and I think I understand/or can follow what you
are trying to do here. The compile went fine but the text
box I created and used the onHand as you explaned below
as the control source, I get the #Name.
Any thoughts on where I must have gone wrong?
Regards,
Mike
-----Original Message-----
Hi Mike
Subtracting the quantity from tblProduct.UnitsIn every
time there is a
transaction won't work.
You could Execute an Update query statement in the
AfterUpdate event of the
form where transactions are entered. But picture this:
I enter a row to order 100 of a product. When I save the
row, the code runs
and subtracts 100 items. Then I realise I should have
typed 10, so I go back
and change 100 to 10. When the record is saved, the code
runs again, and
subtracts 10 items. The field tblProduct.UnitsIn is now
100 less than what
it should be. And have you figured out how to restore
those values when rows
are deleted?
To use the code in the link:
1. In the Database window, click the Module tab, and
then New.
Access opens a code window.
2. From the Tools menu, choose References. Check the box
beside:
Microsoft DAO 3.6 Library (or 3.51 if you
use Access 97).
3. Copy the code from the web page, starting
with "Function ..." and ending
with "End Function".
4. Paste into your module.
5. Choose Compile from the Debug menu to check Access
understands it okay.
6. Save the module. A name like "Module1" will do.
7. Use the function just like any other in Access. For
example, if you have
a form that has a ProductID text box, you can add
another text box with a
Control Source of:
=OnHand([ProductID])
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
What I have done, is a query based on my tblProduct
(which is my Inventory table and has a feild UnitsIn)
and
the tblTransaction (which is used for sending materials
out of the shop and has a feild quantity)). Based on
that
query which deduct Quantity from UnitsIn and give me a
number which is the new unitsIn stock, I have created a
from and that form has become a subform on my
frmTransaction. This gives me the new number after x
quantity is sold. SO no codes have been involved so
far,
but As you can see, there is a problem with this as my
original UnitsIn (Units in Stock) in the Inventory
table
doesn't change.
here what have:
tblOrders (receiveable, has UnitsIn, UnitPrice,
ProductID, ProductName, etc.)
tblProduct (My Inventory, when a ProductID is typed in
the ProductID feild of frmProduct, it gats populated
based on the info from frmReceivable)
tblTransaction (has all the feild for frmOrders,
fromProduct plus the quantity and customer
information).
tblInvoice (has InvoiceNUmber, CustomerName,
InvoiceDate)
and frmInvoice,which is continous, On this from is a
Transaction form in the form of a subform which has all
the feilds of the frmInventory plus the qantity sold).
Above is wrapping up my Inventory database but there
is a
problem as I really don't know how to handel my new
units
in stock.
Also, How one can use the code you posted in your
website?
Regards,
Mike
-----Original Message-----
Mike, how are you doing this?
Are you running an Update query in the AfterUpdate
event
procedure of the
form (frmTransaction)? If so, will your code deduct
the
amount twice if the
user changes something (since Form_AfterUpdate runs
again)?
Will it make the change correctly if the user goes
back
and alters the
quantity in an existing record?
Will it restore the quantities if the user deletes
rows
from frmTransaction?
Even if they select multiple rows for deletion at
once?
For an introduction to the issues, see:
Inventory Control - Quantity On Hand
at:
http://allenbrowne.com/AppInventory.html
I have created an Inventory and Transaction database
but
need to be able to deduct a transaction on an
specific
item from the UnitsInStock in the Inventory
database.
On my frmTransaction which is bounded to my
tblTransaction I have done this deduction based on
querires and it shows me how many units of that
specific
item we have after a Transaction has been made, but
tblInventory still has the old value (Value before a
Transaction) in it. Is ther any way to refelect
these
changes dynamically in to the tblInventory to have
up
to
date and correct values in the table Inventory?
Any help, suggestion on how to approach this problem
and
possibly hints on doing that is greatlly
appreciated.
Thank you in advance for your help.
Regards,
Mike