I have a table (Table1) and I want my users to be able to control the priority. For this question, consider only 2 fields, Priority (as Integer) and Desc (as String).
My form (Form1, Continuous) displays bound textboxes, txtPriority and txtDesc. The user changes the values in txtPriority, and then presses cmdReOrder. This should renumber Priority (in Table1) from 1 to n, and display the records in the new order.
The below code works perfectly, IF CALLED TWICE. In other words, if the statement "Call ReOrder" is 2 identical lines of code, this works as I intended. What little item am I missing here?
My form (Form1, Continuous) displays bound textboxes, txtPriority and txtDesc. The user changes the values in txtPriority, and then presses cmdReOrder. This should renumber Priority (in Table1) from 1 to n, and display the records in the new order.
The below code works perfectly, IF CALLED TWICE. In other words, if the statement "Call ReOrder" is 2 identical lines of code, this works as I intended. What little item am I missing here?
Code:
Private Sub cmdReOrder_Click()
Call ReOrder
End Sub
Private Sub ReOrder()
Dim wkSQL As String
Dim i As Integer
wkSQL = "SELECT Table1.Priority " & _
"FROM Table1" & _
"ORDER BY Table1.Priority;"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(wkSQL)
i = 1
Do Until rst.EOF
rst.Edit
rst!Priority = i
rst.Update
rst.MoveNext
i = i + 1
Loop
rst.Close
dbs.Close
Me.Requery
End Sub
Comment