Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. looping through first row of datagrid without moving onto next

looping through first row of datagrid without moving onto next

Scheduled Pinned Locked Moved Visual Basic
helpquestiondatabase
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mcm
    wrote on last edited by
    #1

    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!

    Richard DeemingR 1 Reply Last reply
    0
    • M mcm

      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!

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      mcm wrote: Do Until .EOF .MoveFirst Call Save(iOrderNo, strCode, strDesc, iQuantity, iFullPrice) .MoveNext Loop This code:

      1. Moves to the first record;
      2. Saves the record;
      3. Moves to the next record;
      4. Goes back to the start of the loop;
      5. Tries to move to the first record;
      6. 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

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups