Okay, I'm not sure even where to begin with this one. I know what I need to do, and can map it out in pseudo-code but have no idea where to begin with Access/VBA.

Background: I needed to create a simple database with a local social services organization to keep track of their holiday assistance funds. Each client will get a voucher to use at the local grocery store to purchase food for their holiday meal. My problem is that there are (right now) two different funds that the money needs to come out of. I want to leave it open to the possibility of doing more in the future.

I have a table with three fields, fundID(text), fundName(text), and fundCap(currency). How it will work, no matter how many funds there are, is that all but one will have a cap. I have a query, named fundSort that has 3 fields, fundID, fundCap, and fundAmt. fundAmt is a calculated field from another query that tallies the total amount currently assigned to that fund. The query is sorted descending by the fundCap, so basically the fund with the largest cap goes first, and the last fund will have a cap of zero, which means there is no cap.

Then I have a table that is called voucherInformation. This table has primarySSN (the primary key, a 1to1 relationship with my main table that has all the applicant information in it), numInFamily, voucherAmt(currency, previously calculated and entered into the table by means of an update query), and fundID.

So what I need to do basically, is a nested loop:
For Each Record in the fundSort Query:
-get fundID and store in a variable
-get fundCap and store in a variable
-get fundAmt and store in a variable
	If fundCap=0 (this means that there is no cap)
		For Each record in the voucherInformation Table:
			If fundID isNull:
				set fundID field = to the fundID
	ElseIf fundCap-fundAmt>0 (meaning there is still room in the fund)
		For Each Record in the voucherInformation Table:
			If fundID isnull:
				If fundAmt + voucherAmt <= fundCap
					set fundID field = to the fundID
					add voucherAmt to the fundAmt variable we set before
I don't even know if this is going to make any sense to anyone, but if anyone can tell me how to go about doing this, it would be a big help.