Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2009
    Posts
    48

    Unanswered: MoveNext Doesn't Work

    The code snippet between the dashed lines fails because it does not move to the next record and thus is an endless and useless loop. Debugging shows that the MoveFirst and MoveLast commands work, but not the MoveNext command. What am I doing wrong?


    Public Function concat_fields()

    Dim rst As DAO.Recordset
    Dim rstParts As DAO.Recordset
    Dim db As DAO.Database
    Dim Hold_Field As String
    Dim strPartName As String
    Dim strPartNum As String


    Set db = CurrentDb


    (other code)


    rstParts.Index = "PartName"
    rstParts.MoveFirst
    --------------------------------------------------------------------------
    Do While Not rstParts.EOF
    If rstParts![Vendor #2] = strPartNum And rstParts!PartName = strPartName Then
    rstParts.Edit
    rstParts!Description = Hold_Field
    rstParts.Update
    End If
    rstParts.MoveNext
    Loop
    --------------------------------------------------------------------------
    (other code)

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    I don't actually see a problem with that, the MoveNext should work. However, it would be much more efficient to execute an UPDATE query with the appropriate criteria than to open a recordset on the whole table and loop through the records.
    Paul

  3. #3
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    I can't see anything wrong with it either.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  4. #4
    Join Date
    May 2009
    Location
    Ottawa, Canada
    Posts
    11
    Different then how I do a loop like that, I would usually have it like:

    Code:
    --------------------------------------------------------------------------
    Do
    If rstParts![Vendor #2] = strPartNum And rstParts!PartName = strPartName Then
    rstParts.Edit
    rstParts!Description = Hold_Field
    rstParts.Update
    End If
    rstParts.MoveNext
    Loop Until rstParts.EOF = True
    --------------------------------------------------------------------------
    But as for your code, it looks fine to me at first glance... Unless you need an " = True" for a While NOT .EOF statement, which me thinks you wouldn't, but my brain is pretty scattered right now.

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    does this code crap out, are there any errors
    is one or more of the columns string / text if so that element will need to be encapsualted

    eg
    where myStringPart = "blah-di-blah"
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    Join Date
    Jun 2009
    Posts
    48
    strPartNum, strPartName, and Hold_Field are all Dim String. No, there are no error messages. I have put a break point in the code though or the loop will run forever since it never moves from the first record. In a later version of the loop I had it break out of the loop if it modifed the Description field (also a string). Of course it never meets the criteria and does exit for EOF either. I can tell from the watches I set that it never leaves the first record in the table (ordered by PartName).

  7. #7
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Is the .Update succeeding?

    I'm kinda at a loss, I have never had a .MoveNext fail :/
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •