Go Premium for a chance to win a PS4. Enter to Win

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

BOF and EOF problems

My research has failed, so here goes!  

Why does this stop movement to the previous form when I am currently not on the first record?  I am right now on record 7, and when I click on Previous button, it exits the sub.  If I put Not  before the rst.BOF, then it moves until I get to the first one, then another click gives an error message.  

What's wrong?  
Susan


Private Sub ToPrevious_Click()

    On Error GoTo Err_ToPrevious_Click

      blnEditsOK = False
If SaveMyRecord() = True Then
End If

Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("AQ00SubjectEligEnroll")
Forms![F00-All2].SetFocus

If rst.BOF Then
Exit Sub

        DoCmd.GoToRecord , , acPrevious
End If

Exit_ToPrevious_Click:
    Exit Sub

Err_ToPrevious_Click:
    MsgBox "This is the first record.", vbOKOnly, "First Record"
    Resume Exit_ToPrevious_Click
   
End Sub
0
skennedy10
Asked:
skennedy10
  • 3
  • 3
1 Solution
 
dan_vellaCommented:
Looks like you might be missing the else:

If rst.BOF Then
Exit Sub

ELSE
        DoCmd.GoToRecord , , acPrevious
End If
0
 
ClothahumpCommented:
Agreed.  Either put in the Else or change it to


If NOT rst.BOF Then
        DoCmd.GoToRecord , , acPrevious
End If
0
 
skennedy10Author Commented:
OK, I added the "Else" and I was able to move backward until I got to 1, then on that click I get this error:  

Runtime error '2105':You cannot go to the specified record.  --the same thing that I get without all this recordset clone stuff and BOF!  

It just does not seem to evaluate when it is at BOF right.  

What causes that?
Susan
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
dan_vellaCommented:
What is your aim with this? You could just use

DoCmd.GoToRecord , , acPrevious

on its own if navigation is the only purpose
0
 
skennedy10Author Commented:
I don't want an error message  (the runtime error 2105) if already at the first record and the user hits Previous Record button.  

I have done the NOT rst.BOF then ..... also, and it just does not seem to pick up on being BOF!  

I noticed that there are ADO and DAO recordset types and that they are different.  Do I have the wrong one?  I get past that in code stepping, so I assumed I had that right.  

Susan


0
 
dan_vellaCommented:
Susan,

Using the default previous button via the MS Access wizard accomplishes this, unless there was something else you need the code to do.

It gives the default message "Can't go to the specified record".
0
 
skennedy10Author Commented:
Gentlemen,
Thanks for all of your help.  I figured out that I had gone to Tools/Options/General and had checked "Break on unhandled errors."  

This was not letting the BOF "normal message" you thought I was referring to show.  I was getting the one that told me that I had an error (with #) and was asking to either end or debug, which I don't want the user to have to deal with.  

Thanks!
Susan
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

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