looping through first row of datagrid without moving onto next
-
Here is a basic structure of my code: Private Sub cmdConfirm_Click() With Adodc3.Recordset Do Until .EOF .MoveFirst Call Save(iOrderNo, strCode, strDesc, iQuantity, iFullPrice) .MoveNext Loop End With Function Save(iOrderNo As Integer, strCode As String, strDesc As String, iQuantity As Integer, iFullPrice As Integer) as boolean .....validation statements and inserts If Val(DataGrid2.Columns("Quantity").Value) > RS("Quantity").Value Then Call BackOrder(strCode, strDesc, iQuantity) End If Save = True Function BackOrder(strCode As String, strDesc As String, iQuantity As Integer) As Boolean ....validation and inserts BackOrder = True To step through the code briefly, when the command button is pressed, a save function is called (for each row in the datagrid), which performs the necessary validation and saves to the database, this also calls another function - BackOrder, which enters products in a backorder if necessary. I hope the information given is sufficient, and if not, please let me know. The problem occurs when the project is run, there must be something wrong with the loop as it runs through the first row twice, upon which a bug is thrown, without ever moving onto the next row...why is this - how can i make it run through all the rows? Thank you so much - any help would be greatly appreciated!
-
Here is a basic structure of my code: Private Sub cmdConfirm_Click() With Adodc3.Recordset Do Until .EOF .MoveFirst Call Save(iOrderNo, strCode, strDesc, iQuantity, iFullPrice) .MoveNext Loop End With Function Save(iOrderNo As Integer, strCode As String, strDesc As String, iQuantity As Integer, iFullPrice As Integer) as boolean .....validation statements and inserts If Val(DataGrid2.Columns("Quantity").Value) > RS("Quantity").Value Then Call BackOrder(strCode, strDesc, iQuantity) End If Save = True Function BackOrder(strCode As String, strDesc As String, iQuantity As Integer) As Boolean ....validation and inserts BackOrder = True To step through the code briefly, when the command button is pressed, a save function is called (for each row in the datagrid), which performs the necessary validation and saves to the database, this also calls another function - BackOrder, which enters products in a backorder if necessary. I hope the information given is sufficient, and if not, please let me know. The problem occurs when the project is run, there must be something wrong with the loop as it runs through the first row twice, upon which a bug is thrown, without ever moving onto the next row...why is this - how can i make it run through all the rows? Thank you so much - any help would be greatly appreciated!
mcm wrote: Do Until .EOF .MoveFirst Call Save(iOrderNo, strCode, strDesc, iQuantity, iFullPrice) .MoveNext Loop This code:
- Moves to the first record;
- Saves the record;
- Moves to the next record;
- Goes back to the start of the loop;
- Tries to move to the first record;
- Throws an error because you have a forward-only recordset;
Change the loop to:
Do Until .Eof
' TODO: Get these values from the recordset!
Call Save(iOrderNo, strCode, strDesc, iQuantity, iFullPrice)
.MoveNext
Loop
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer