Results 1 to 9 of 9
  1. #1
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246

    Problem with While Wend code. Works on one form but doesn't work correctly on another form.

    I have two separate continuous forms. When the end user opens the form it may have 20 records. The form sets the focus on the first record, first field. The end user tabs through the record entering data. When the user Exits the last field in the record, it executes an On Exit Event and a While Wend runs going to the Next Record and this repeats until the user gets to the last record on the form and then it stops. This runs perfectly.



    It is the exact same setup and procedure on the second form. When the end user opens the form it may have 50 records. The form sets the focus on the first record, first field. The end user tabs through the record and when the user exits the last field on the form the exact same While Wend runs.

    But it does not go to the next record. Instead it jumps to the last record on the form and sets the focus on the correct field. It skips all the records in between. It should go to the next record until it gets to the end. I don't see anything wrong. Here is my code for both While Wends.

    Code:
    Private Sub UnitNO_Exit(Cancel As Integer)
    While Me.CurrentRecord < Me.recordset.RecordCount
    DoCmd.GoToRecord record:=acNext
    Me.kPIN7.SetFocus
    Wend
    End Sub
     
    Private Sub Memo_Exit(Cancel As Integer)
    While Me.CurrentRecord < Me.recordset.RecordCount
    DoCmd.GoToRecord record:=acNext
    Me.AOPropAVLand.SetFocus
    Wend
    End Sub
    Thanks, Phred

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    What is purpose of looping? Why move to each record? Other than setting focus on a control, nothing else is accomplished within this loop, why move to each record?

    Don't see anything wrong with code and cannot replicate the issue.

    Have you step debugged? Review link at bottom of my post for debugging guidelines.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246
    I just want the tab go-to-next-record process to stop when the user reaches the last record on the form. Is there some simpler way?

    New records are not allowed so they can't add a new record Allow Additions=No. This is the first idea I found after searching that worked. I don't get any errors when I step through it. I am open to other ideas.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Could just move directly to last record.

    Docmd.GoToRecord , , acLast

    Use the comma syntax and will see parameter options for the arguments.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246
    I'm really confused. If there are 60 records on the form and they are in the first record, enter all the data, get to the last field. When they tab out it goes to the next record on the form. If the command is as you suggest won't the jump to the last record on the form? I want them to go to the next record until they get to the last record and then stop.

    docmd.gotorecord,,acLast jumps from the first record to the last record. I want it to go to the next record.

    If I use acNext:

    docmd.gotorecord,,acNext it then goes to the next record fine. When I get to the last record in the form with acNext I get Run-Time error '2105' You can't go to the specified record.

    This is why I switched to the code above. It stops without any error at the last record. Except on the screen that errors.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    So am I. I tested your looping code. It caused the focus to set to each record until it reached the end - I could see the navigation. It did not stop at the second record to allow me to enter data, it went all the way to last record. This is what you described as desired behavior. If you want to stop on the next record then don't use looping construct, use If Then instead.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246
    Can you give me an example of how the if then would work for this?

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    If Me.CurrentRecord < Me.recordset.RecordCount Then
    DoCmd.GoToRecord , , acNext
    Me.AOPropAVLand.SetFocus
    End If
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246
    Well I would have not thought of that. It looks so simple. I will implement it this weekend and let you know how it works.

    Thanks Much.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 06-26-2015, 06:00 PM
  2. similar code, one works, the other doesn't
    By johnseito in forum Access
    Replies: 15
    Last Post: 11-03-2013, 07:59 PM
  3. Why 'for next' works but 'while wend' does not
    By lawdy in forum Programming
    Replies: 4
    Last Post: 02-03-2013, 02:59 PM
  4. Replies: 6
    Last Post: 09-02-2012, 04:30 PM
  5. Replies: 2
    Last Post: 07-23-2011, 08:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums