Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Nov 2002
    Location
    New York, New York, USA
    Posts
    266
    Thanks
    0
    Thanked 19 Times in 19 Posts

    Loop does not End (Acess 2003)

    The following code is intended to step through a recordset until one text box matches the other at which point the loop should end. The loop is in the oncurrent function of the Form.
    When the code runs and the values match the loop ends and the code advances to end sub but it does not end at this point as expected rather it jumps back to the previous record in the recordset and restarts the loop which then causes an infinite loop. How can I End this Sub Procedure

    Any assistance is appreciated.


    Sub Form_Current()

    If FindIssueFlag = True Then

    Dim rsFind As Recordset
    Set rsFind = Me.Recordset

    Do Until Me.txtTemp.Value = Me.txtIssueID.Value
    rsFind.MoveNext
    Loop
    End If

    FindIssueFlag = False

    End Sub

    Regards,

    Tom Duthie

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Loop does not End (Acess 2003)

    Since Me.Recordset is the record source of the form, rsFind.MoveNext causes the On Current event to fire again. You shouldn't be calling this code from the On Current event of the form. Perhaps you could call it from the On Load event?

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Loop does not End (Acess 2003)

    When you have a bound form, any "looping" through the recordset should be done against the RecordSetClone, not the recordset itself. Change start of your code to this:

    Set rsFind = Me.RecordSetClone
    rsFind.bookmark = me.bookmark

    At the end, use this code to set your form to the found record, if one is found:

    if Me.EOF = False Then
    Me.bookmark = rsFind.Bookmark
    End if
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  4. #4
    3 Star Lounger
    Join Date
    Nov 2002
    Location
    New York, New York, USA
    Posts
    266
    Thanks
    0
    Thanked 19 Times in 19 Posts

    Re: Loop does not End (Acess 2003)

    Edited by HansV to remove large number of superfluous empty lines.

    Dear Mark and Hans:

    With you suggestions and our determination the following code works in all situations. It may not be the best code but it works

    Sub Form_Current()
    On Error Resume Next
    Dim rst As Recordset
    Dim lngCount As Long
    Dim Count As Integer
    Dim rsFind As Recordset

    'This code displays the "Record # of #" label on my form
    Set rst = Me.RecordsetClone
    With rst
    .MoveFirst
    .MoveLast
    lngCount = .RecordCount
    End With
    Me.txtRecordCounter = "Record " & Me.CurrentRecord & " of " & lngCount

    'The rest of this code loops until the values in txtTemp and txtIssueID match in a given recordset (essentially a find function). Every

Posting Permissions

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