I wanted to ask if it is possible to update multiple records in a continuous form at once. I currently have a button that updates the record how I want it to, but it only does it for 1 record at a time and not all records displayed within the form. Is this possible to do?
So just in a brief summary, I have an inventory/order database I'm working on. The form in question is a subform within a mainform. The main form is an order form and has 2 subforms.
Subform1 is a product list where they select the products they want to order
Subform2 is an "item cart" where the selected products go from subform1
So when I click a "submit order" button which is in subform2, I want it to update the product amounts from all the products in the cart. Basically adjusting the onhand inventory (deducting the qty ordered from each product). Like I said, my button does the first record perfectly, but I cant find anything that lets you do all the records at once. If a customer orders 25 products, I don't want them or myself to have to individually click a button for all 25 products. Surely there's something that can loop through all the records and adjust each one within the order? Here is my code so far:
Code:
Private Sub cmdSubmit_Click()10 On Error GoTo cmdUpdateStock_Click_Error
20 If Me.Dirty Then Me.Dirty = False
Dim rsTemp As DAO.Recordset
Dim strSQL As String
'Create a copy of this forms Recordset
30 Set rsTemp = Me.RecordsetClone
40 rsTemp.MoveFirst
50 Do Until rsTemp.EOF
'Loop through all records and update records....
60 strSQL = "UPDATE tblProducts SET QtyAvailable = " & Me.NQA _
& " WHERE ProductID = " & Me.ProductID & ";"
70 Debug.Print strSQL
80 CurrentDb.Execute strSQL, dbFailOnError
90 rsTemp.MoveNext
100 Loop
'Release resources
110 MsgBox "Your order has been successfully submitted", vbInformation, "Success"
120 rsTemp.Close
130 Set rsTemp = Nothing
140 [Forms]![frmOrderDetails]![frmItemCartOrdersSubform].[Form].Requery
150 On Error GoTo 0
160 Exit Sub
cmdUpdateStock_Click_Error:
170 MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdUpdateStock_Click, line " & Erl & "."
End Sub
I also have a txt box I put in the subform for referencing. It is set to not be visible but is the total of the QtyAvailable - QtyOrdered and is called "NQA" (New Qty Available) which is in the code and is the value I want the products to be adjusted to in tblProducts. Any suggestions or tips would be much appreciated. I really want to be able to get this working on all the records in the item cart without doing it individually.
Thanks,
Kip