Results 1 to 6 of 6
  1. #1
    cebrower is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2018
    Location
    Spring Lake, MI
    Posts
    110

    Test for no more records in a form

    I want to loop through the records in a form using the following structure:

    DoCmd.OpenForm "MyForm"



    Do While IsNull(MyForm!FieldName) = False
    'Execute some commands
    DoCmd.GoToRecord,,acNext
    Loop

    Normally the last record in the form is blank, so MyForm!FieldName is null. I've used this format successfully in many places, but now I have a form that does not have a blank record at the end and I get an error message that I can't go to the next record. In the form properties I allow additions, but there is no blank record. How can I tell when I've reached the last record?

    Thanks for any suggestions.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,523
    Simplest might be to trap for the error number and handle it as desired. If needed:

    http://www.baldyweb.com/ErrorTrap.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,945
    Consider
    Code:
    Do While IsNull(MyForm!FieldName) = False
         'do something
         Me.RecordsetClone.Bookmark = Me.Bookmark
         If Not Me.RecordsetClone.EOF ThenDoCmd.GoToRecord , , acNext
    Wend
    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.

  4. #4
    cebrower is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2018
    Location
    Spring Lake, MI
    Posts
    110
    Thanks for the suggestions. I trapped the error and that did the job.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,523
    Glad you got it working.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Why not
    Code:
        
        With Me.RecordsetClone
            .MoveFirst
            While Not .EOF
                'Do something
                .MoveNext
            Wend
        End With
    ?

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

Similar Threads

  1. Replies: 25
    Last Post: 11-23-2014, 02:43 PM
  2. Test String test besed on table data
    By igourine in forum Programming
    Replies: 3
    Last Post: 12-01-2013, 06:16 AM
  3. Replies: 8
    Last Post: 11-20-2012, 10:32 PM
  4. Test if Form is Open
    By wdrspens in forum Programming
    Replies: 6
    Last Post: 06-13-2011, 03:39 PM
  5. Keying in Test answers to Access DB from Written Test
    By CityOfKalamazoo in forum Access
    Replies: 3
    Last Post: 03-01-2010, 08:58 AM

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