Looping in a Subform

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ccookson
    New Member
    • Feb 2008
    • 4

    Looping in a Subform

    The following code is part of a button (on click) that places a check (true) in a filtered subform. The subform is a set of continuous forms. The checks are placed but it gives an error message that it can’t go to the next record. When I try to step through it, a check is placed in the first record but errors out before it starts to loop?
    Code:
    x = Me.Text6
    Screen.PreviousControl.SetFocus
    DoCmd.GoToRecord , , acFirst
    
        Do While x > 1
        Me.Check48 = True
        DoCmd.GoToRecord , , acNext
        x = x - 1
        Loop
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Originally posted by ccookson
    ...The checks are placed but it gives an error message that it can’t go to the next record. When I try to step through it, a check is placed in the first record but errors out before it starts to loop?

    x = Me.Text6
    Screen.Previous Control.SetFocu s
    DoCmd.GoToRecor d , , acFirst

    Do While x > 1
    Me.Check48 = True
    DoCmd.GoToRecor d , , acNext
    x = x - 1
    Loop
    When you say it errors before it starts to loop, is it when you execute the Docmd.GotoRecor d statement? If so, it is likely to be because you have not stored the current record which has been updated. If the error is at the GotoRecord, add a save statement just before it:
    Code:
    DoCmd.Save ,,
    -Stewart

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32656

      #3
      Can you tell us which line the error occurs on and what the error message is?

      Comment

      • ccookson
        New Member
        • Feb 2008
        • 4

        #4
        the error occurs at the "DoCmd.GoToReco rd , , acNext"

        I have added a save just before the DoCmd.GoToRecor d , , acNext:
        Code:
            Do While x > 0
            Me.Check48 = True
            DoCmd.Save
            DoCmd.GoToRecord , , acNext
            x = x - 1
            Loop
        However, this still results in the same error

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32656

          #5
          ... and what the error message is?

          Comment

          • ccookson
            New Member
            • Feb 2008
            • 4

            #6
            Sorry...

            Run-time error '2105':

            You cant go to the specified record

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32656

              #7
              I would have expected that Scott was right about the save. I can see no other reason why going to the next record might fail. Is there a next record? Maybe there are no more records in your recordset. I'm grasping at straws here as I really can't see the problem. I'm sorry.

              Comment

              Working...