What is wrong with my code??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tlyczko

    #1

    What is wrong with my code??

    I am writing code to get a subset of table records, but it is not
    looping properly through the fields, it keeps getting stuck in some
    sort of infinite loop and I have to be able to walk the whole
    recordset.

    Am I not using the do loop properly??

    dim db as DAO.database
    dim rs3 as DAO.recordset
    dim strSQL as string
    strSQL = "SELECT tblComments.Aud itID, tblComments.txt Topic,
    tblComments.mem AuditTopicComme nts"
    strSQL = strSQL & " FROM tblComments"
    strSQL = strSQL & " WHERE tblComments.Aud itID=" & lngAuditID
    Set rs3 = db.OpenRecordse t(strSQL)
    rs3.MoveFirst
    rs3.MoveLast
    Do Until rs3.EOF
    'this should show different values, but gets stuck on the value of the
    last record
    MsgBox rs3.Fields("txt Topic").Value
    Loop

    I actually need to run a Select Case statement inside the Do loop to
    update various records in the recordset, it is a small recordset, <20
    records.

    Thank you, Tom

  • Lyle Fairfield

    #2
    Re: What is wrong with my code??

    Do Until rs3.EOF
    MsgBox rs3.Fields("txt Topic").Value
    Loop

    Comment

    • Joost

      #3
      Re: What is wrong with my code??

      rs3.MoveLast moves the current record to the last record of the
      recordset so rs3.EOF
      is always inmediately true so that's why you get stuck on the value of
      the
      last record

      Try

      rs3.MoveFirst
      Do Until rs3.EOF
      MsgBox rs3.Fields("txt Topic").Value
      rs3.moveNext
      Loop

      Succes

      Comment

      • tlyczko

        #4
        Re: What is wrong with my code??

        Hello Lyle,
        Please excuse me, I cannot see any difference between your suggestion
        and my code that I posted above.
        Please tell me the difference between what you typed and what I have??
        My code gets stuck in an endless loop when it should show 8-10
        different values per recordset.
        Thank you, Tom

        Comment

        • tlyczko

          #5
          Re: What is wrong with my code??

          Duh!! MoveNext.
          Something simple. :) :) :)
          Thank you, Joost.
          :) tom

          Comment

          • Lyle Fairfield

            #6
            Re: What is wrong with my code??

            That's because I was stupid.

            Comment

            • Jeff

              #7
              Re: What is wrong with my code??

              Hi Tom

              Do Until rs3.EOF
              MsgBox rs3.Fields("txt Topic").Value

              rs3.MoveNext
              Loop

              You need the 'MoveNext' to move to the next record.

              Jeff Pritchard
              _______________ _
              Asken Research Pty. Ltd.
              Access Database Developers


              "tlyczko" <tlyczko@gmail. com> wrote in message
              news:1141068756 .951676.210610@ t39g2000cwt.goo glegroups.com.. .[color=blue]
              >I am writing code to get a subset of table records, but it is not
              > looping properly through the fields, it keeps getting stuck in some
              > sort of infinite loop and I have to be able to walk the whole
              > recordset.
              >
              > Am I not using the do loop properly??
              >
              > dim db as DAO.database
              > dim rs3 as DAO.recordset
              > dim strSQL as string
              > strSQL = "SELECT tblComments.Aud itID, tblComments.txt Topic,
              > tblComments.mem AuditTopicComme nts"
              > strSQL = strSQL & " FROM tblComments"
              > strSQL = strSQL & " WHERE tblComments.Aud itID=" & lngAuditID
              > Set rs3 = db.OpenRecordse t(strSQL)
              > rs3.MoveFirst
              > rs3.MoveLast
              > Do Until rs3.EOF
              > 'this should show different values, but gets stuck on the value of the
              > last record
              > MsgBox rs3.Fields("txt Topic").Value
              > Loop
              >
              > I actually need to run a Select Case statement inside the Do loop to
              > update various records in the recordset, it is a small recordset, <20
              > records.
              >
              > Thank you, Tom
              >[/color]


              Comment

              • tlyczko

                #8
                Re: What is wrong with my code??

                No, I was. :)
                I forgot the MoveNext.
                Thank you!
                :) tom

                Comment

                Working...