Hey all,
I wanted to loop through a series of numbers and use them as criteria in a DSum function in an If Statement. This probably is very clear, but once you see the code you'll understand.
Code:
Private Sub Command0_Click()
Dim prdtID As Long
For prdtID = 1 To 450
If Application.DSum("Quantity", "TakeIn", "ProductID = " & prdtID & "") - Application.DSum("Quantity", "TakeOut", "ProductID = " & prdID & "") < 6 Then
Dim rstLessThan5 As DAO.Recordset
Set rstLessThan5 = CurrentDb.OpenRecordset("Lessthan5")
With rstLessThan5
.AddNew
.Fields("ProductID") = prdtID
.Fields("ProductName") = "?"
.Fields("ProductModel") = "?"
.Fields("Quantity Left") = Application.DSum("Quantity", "TakeIn", "ProductID = " & prdtID & "") - Application.DSum("Quantity", "TakeOut", "ProductID = " & prdID & "")
.Update
End With
End If
Next
End Sub
The point is to find the difference between items taken out of the stop and items put into the shop to see how much inventory is left over. If the amount left over is less than 6, the product ID, name, model, and left over quantity will be put onto a table to be made into a report. As of right now, I'm running through a series of numbers 1 to 450. I'm getting stuck on the DSum criteria where i try to use this variable. I think somethings wrong with the " and & and # around the variable. I'm also don't know how to refer to the product name and model that are associated with each product ID so it can be inserted into the table. Also, is it possible to have access look up my product ID from a field on a table instead of cycling through 1 to 450 like this?
Thanks guys!