Right – many thanks so far however I am trying and getting nowhere fast!
So as a quick summary I am trying to have a database working on a FIFO basis and record items.
Having taken the previous database, I am tyring to adapt it.
I have a few tables:
1. Products (no and name)
2. Customers (no and name)
3. purchase, which is just an ID and date,
4. purchase detail, which will be a subform of purchase having product item, quantity and price
5. Stock, which holds stock no, purchase date, stock item(product no), stock quantity (quanity) and stock price(price), and out of stock (yes/no)
So when I enter a purchase on the purchase form, I want it to copy the records to the stock table. The reason for this is having a complete purchase ledger, and a stock ledger which can be added to and removed when stock is sold. (And the sales cost calculated.)
I tried to set up a loop where you would count the number of items in the subform and loop n times to add records to stock using the same purchase date and default out of stock to false to no avail, as it didn’t seem to like the way I wrote
tquant

= me.suform.purchase_detail.puq
And then copied this into stock
Docmd.stock,, acnewrec
Stq=tquant
Part 2 of the problem is the same in reverse where on processing a sales quantity and price a corresponding reduction in the stock would happen – this is where I have no idea how to start!
But… what I want is to
1. Check to see if the order can be fulfilled – ie that sold q is < total stq (in a query) if not write a message. Or else:
2. Filter stock for all out of stock false and product id
3. Sort items by purchase date
4. if sold q < first stock line (Stq)
a. then copy stock date(std), stock price (stpr) and sold q to a new table sales purchase ( which links to the sales detail record)
b. subtract soldq from Stq
5. else if sold q > first stock line (stq) Then
a. then copy stock date(std), stock price (stpr) and stock quanity to stock quantity(stq) to a new table sales purchase ( which links to the sales detail record)
b. put stq to 0 for that line and make out of stock true.
c. Sold q = sold q –stq for that line
d. Refilter for all out of stock = false
e. Loop from 4 till order fulfilled.
Sorry if this is a long boring process – but having read some of the more complex coding solutions I was wondering the best way to do this? I have attached my DB for any help.
Thanks a lot in advance!