[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

unable to trap EOF & BOF I no it simple but I can not see where I am going wrong

I have written some buttons on my form to move through the records.  I am unable to get them to stop when they get the end of the file or Begining of the file the code Iam using is a follows

If Not Me.Recordset.EOF Then DoCmd.GoToRecord , , acNext

If have also tried

If Not Me.Recordset.EOF = true  Then DoCmd.GoToRecord , , acNext

I no it is something stupied any idears
0
locka
Asked:
locka
1 Solution
 
JohnK813Commented:
Will this suit your needs?

While Not Me.Recordset.EOF
  DoCmd.GoToRecord , , acNext
Wend

You could also try the command

Me.RecordSet.MoveNext

instead of the DoCmd line.
0
 
GreymanMSCCommented:
You have a boundary condition error in your logic.
 
EOF is true only when you have gone PASSED the last record in the set, but not when you are just ON it.  Likewise with BOF and the first record.  That's why your code is never doing what you expect on the last and first records.
 
You'll need to first attempt to move, THEN to roll back if you've gone to an EOF or BOF.  Even better, test a move using a Recordset.Clone before before actually making it on the Recordset itself.
0
 
lockaAuthor Commented:
found this code to solve my problems it also allows me to disable buttons that are unaviable.

Private Sub previous_Click()
If Me.CurrentRecord = 1 Then
   Me.Next.Enabled = True
   Me.Next.SetFocus
   Me.previous.Enabled = False
Else
    DoCmd.GoToRecord , , acPrevious
   Me.previous.Enabled = True
End If
End Sub
Private Sub Next_Click()
If Me.CurrentRecord = Me.RecordsetClone.RecordCount Then
    Me.previous.Enabled = True
    Me.previous.SetFocus
    Me.Next.Enabled = False
Else
    DoCmd.GoToRecord , , acNext
    Me.Next.Enabled = True
End If
End Sub
0
Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
JohnK813Commented:
If you've answered this yourself, feel free to ask for a refund here: http://www.experts-exchange.com/Community_Support/
0
 
lockaAuthor Commented:
I will when I get rounf to it.  Thanks for your help though I did try your example but all that happned was it scrolled quickly though your record set.
0
 
JohnK813Commented:
Ah, yes, I see I misread the question a bit.  It looks like your solution is the thing to do in your case (obviously).
0
 
PAQ_ManCommented:
PAQed with points refunded (50)

PAQ_Man
Community Support Moderator
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now