I'm new to modules/VBA so please forgive any stupid questions 
I'm trying to write a function in a query to allocate material from work orders to fill sales order demand. It's currently a many to many relationship so I'm getting multiple records per sales order for each work order for the same item. I have 2 tables:
Table name: tblSalesOrderDemand
Fields:
strID strSO lngReqd dteDueDate
482 407751 50 6/4/09
482 407752 50 6/10/09
Table name: tblWorkOrders
Fields:
strWONum strID lngQty
77501-99 482 25
77502-99 482 30
77503-99 482 100
Desired result:
tblWorkOrderAlloc
Fields:
strID strSO lngReqd dteDue strWONum lngAlloc lngWOAvail
482 407751 50 6/4/09 77501-99 25 0
482 407751 50 6/4/09 77502-99 25 5
482 407752 50 6/10/09 77502-99 5 0
482 407752 50 6/10/09 77503-99 45 55
I have hundreds of sales order demand records and 1-10+ work orders for each item. At this point, I'm not concerned with the due date on the work order (it's a dynamic manufacturing environment and changes too fast!)
The only way I can see to accomplish this would be to read tblSalesOrderDemand, find the associted strID in tblWorkOrders, loop thru it consuming lngQty until EOF and writing out to tblWorkOrderAlloc until next strID.
As I'm a beginner in writing functions/modules, the only thing I've been able to write is If-Then statements and those get me so far.
Any suggestions?

I'm trying to write a function in a query to allocate material from work orders to fill sales order demand. It's currently a many to many relationship so I'm getting multiple records per sales order for each work order for the same item. I have 2 tables:
Table name: tblSalesOrderDemand
Fields:
strID strSO lngReqd dteDueDate
482 407751 50 6/4/09
482 407752 50 6/10/09
Table name: tblWorkOrders
Fields:
strWONum strID lngQty
77501-99 482 25
77502-99 482 30
77503-99 482 100
Desired result:
tblWorkOrderAlloc
Fields:
strID strSO lngReqd dteDue strWONum lngAlloc lngWOAvail
482 407751 50 6/4/09 77501-99 25 0
482 407751 50 6/4/09 77502-99 25 5
482 407752 50 6/10/09 77502-99 5 0
482 407752 50 6/10/09 77503-99 45 55
I have hundreds of sales order demand records and 1-10+ work orders for each item. At this point, I'm not concerned with the due date on the work order (it's a dynamic manufacturing environment and changes too fast!)
The only way I can see to accomplish this would be to read tblSalesOrderDemand, find the associted strID in tblWorkOrders, loop thru it consuming lngQty until EOF and writing out to tblWorkOrderAlloc until next strID.
As I'm a beginner in writing functions/modules, the only thing I've been able to write is If-Then statements and those get me so far.
Any suggestions?