Results 1 to 8 of 8
  1. #1
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Wend untill (XP/2K)

    I am going out of my mind, and I am sure that it is just my stupidity. I cannot get the loop going through all the records on my form to work. I either miss the last record or get an error that it is trying to go to the next record past the end. The form is edit only (you cannot add records). Here is the code and WHAT am i doing wrong?

    intSerial = 1 ' initialize intserial
    intRecCount = Me.Recordset.RecordCount
    DoCmd.GoToRecord , , acFirst

    Do
    ....

    DoCmd.GoToRecord , , acNext
    intRecCount = intRecCount - 1
    Debug.Print intRecCount & " LAST : " & Me.intZehut
    Loop Until intRecCount = 0

    Thanks

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

    Re: Wend untill (XP/2K)

    Say your form displays 4 records. Your code moves to the first, then tries to move to the next record 4 times:
    1 to 2
    2 to 3
    3 to 4
    4 to ?
    If you allowed new records, the 4th step would create a new record.

    You should report on values in the form before moving to the next record, and exit when you're on the last record. Something like

    intSerial = 1 ' initialize intserial
    intRecCount = Me.Recordset.RecordCount
    DoCmd.GoToRecord , , acFirst

    Do
    ...
    Debug.Print intRecCount & " LAST : " & Me.intZehut
    intRecCount = intRecCount - 1
    If intRecCount = 0 Then Exit Do
    DoCmd.GoToRecord , , acNext
    Loop

  3. #3
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Wend untill (XP/2K)

    I got it! The exit do has to be before the goto next record. That was dumb
    Thanks as usual
    Zave

  4. #4
    5 Star Lounger
    Join Date
    May 2001
    Location
    Patterson Lakes, Melbourne, Victoria, Australia
    Posts
    636
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wend untill (XP/2K)

    For Me.Recordset.RecordCount to returnthe number of records in a recordset, you need to movelast first.

    Me.Recordset.Movelast
    intRecCount = Me.Recordset.RecordCount

    But it
    Regards,
    Peter

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

    Re: Wend untill (XP/2K)

    Peter,

    What you write is correct for the RecordCount property of a DAO recordset. Me.Recordset, however, is an ADO recordset, and in my experience, RecordCount returns the correct number of records for ADO recordsets.

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Wend untill (XP/2K)

    That depends on whether a clientside or serverside user is being invoked and the type of recordset that was opened. In some circumstances, RecordCount on an ADO recordset returns simply True or False to indicate whether there are any records.
    Charlotte

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

    Re: Wend untill (XP/2K)

    Charlotte,

    Thanks, my experience with ADO is still limited. The code in this thread obtains a recordset as <form>.Recordset; this has always returned the correct record count for me up to now, but I'll keep an <img src=/S/eyeout.gif border=0 alt=eyeout width=15 height=15>.

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Wend untill (XP/2K)

    A form's recordset is essentially DAO. Forms bound to ADO recordsets aren't updateable anyhow.
    Charlotte

Posting Permissions

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