THE form below shows the items from a product that done need to be purchased because there is enough in stock . but this form allows me to update the allocation for that part . so for example the reqqty for stock number 3096B0010 for this product is 68.8 therefore when i press the update allocation button it will update the alloaction to 425.52 as indicated in the yellow field
what i would like to do is press the update allocation button once and it updates ALL the records at the same time and shows me the results and then i close the form down
the code below i think is a mixture and just needs modifying to suit but i dont know how. any help appreicated
thanks steve
what i would like to do is press the update allocation button once and it updates ALL the records at the same time and shows me the results and then i close the form down
the code below i think is a mixture and just needs modifying to suit but i dont know how. any help appreicated
thanks steve
Code:
Private Sub cmdUpdate_Click()
10 On Error GoTo cmdUpdate_Click_Error
' Dim strSQL As String
' Dim rs As Object
'20 Set rs = Me.RecordsetClone
'30 With rs
'40 Do While Not .EOF
' 'Do Something
'
'50 strSQL = "UPDATE StockList SET Allocation = " & Me.txtAllocation _
' & " WHERE StockNumber = '" & Me.StockNumber & "';"
' Debug.Print strSQL
' CurrentDb.Execute strSQL, dbFailOnError
'60 .MoveNext
'70 Loop
'80 End With
'90 Set rs = Nothing
'100 MsgBox "All Stocklist Items Updated", vbInformation
Dim rsTemp As DAO.Recordset
Dim strSQL As String
'Create a copy of this forms Recordset
20 Set rsTemp = Me.RecordsetClone
30 rsTemp.MoveFirst
40 Do Until rsTemp.EOF
'Loop through all records and update records....
50 strSQL = "UPDATE Stocklist SET Allocation = " & Me.Update _
& " WHERE StockNumber = '" & Me.StockNumber & "';"
60 Debug.Print strSQL
70 CurrentDb.Execute strSQL, dbFailOnError
80 rsTemp.MoveNext
90 Loop
'Release resources
100 MsgBox "The selected item in Stocklist has been Updated", vbInformation
110 rsTemp.Close
120 Set rsTemp = Nothing
140 On Error GoTo 0
150 Exit Sub
cmdUpdate_Click_Error:
160 MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdUpdate_Click, line " & Erl & "."
End Sub