Help would be greatly appreciated from anyone who can me solve this problem.
I have an Issues form and an Issues details subform in a Stock Control application. On the Issues subform the user can enter several items to issued. I would like to update the Stock table with the quantity issued of each item on the subform with the click of a button on the Issues form.
Here's the code in a module I have used
Sub UpdateStock()
Dim db As Database
Dim rstIssues As Recordset
Dim rstStock As Recordset
strSQL1 = "Select IssueID, StockID, Quantity FROM tblIssueDetails WHERE ((([tblIssueDetails]![IssueID])=[Forms]![frmIssues]![IssueID]));"
strSQL2 = "Select StockID , UnitsInStock FROM tblStock;"
Set db = CurrentDb()
Set rstIssues = db.OpenRecordset(strSQL1, dbOpenDynaset)
Set rstStock = db.OpenRecordset(strSQL2, dbOpenDynaset)
Do While Not rstIssues.EOF
rstStock.Edit
If rstPurchases![StockID] = rstStock![StockID] Then
rstStock![UnitsInStock] = rstStock![UnitsInStock] + rstPurchases![Quantity]
End If
rstStock.Update
rstIssues.MoveNext
Loop
End Sub
I get an error message saying “… not enough arguments. 1 Expected”. Also only the first item on the sub form is updated.
I have an Issues form and an Issues details subform in a Stock Control application. On the Issues subform the user can enter several items to issued. I would like to update the Stock table with the quantity issued of each item on the subform with the click of a button on the Issues form.
Here's the code in a module I have used
Sub UpdateStock()
Dim db As Database
Dim rstIssues As Recordset
Dim rstStock As Recordset
strSQL1 = "Select IssueID, StockID, Quantity FROM tblIssueDetails WHERE ((([tblIssueDetails]![IssueID])=[Forms]![frmIssues]![IssueID]));"
strSQL2 = "Select StockID , UnitsInStock FROM tblStock;"
Set db = CurrentDb()
Set rstIssues = db.OpenRecordset(strSQL1, dbOpenDynaset)
Set rstStock = db.OpenRecordset(strSQL2, dbOpenDynaset)
Do While Not rstIssues.EOF
rstStock.Edit
If rstPurchases![StockID] = rstStock![StockID] Then
rstStock![UnitsInStock] = rstStock![UnitsInStock] + rstPurchases![Quantity]
End If
rstStock.Update
rstIssues.MoveNext
Loop
End Sub
I get an error message saying “… not enough arguments. 1 Expected”. Also only the first item on the sub form is updated.