Solved

BOF and EOF problems

Posted on 2006-11-30
7
373 Views
Last Modified: 2012-05-05
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
Comment
Question by:skennedy10
  • 3
  • 3
7 Comments
 
LVL 4

Expert Comment

by:dan_vella
ID: 18048433
Looks like you might be missing the else:

If rst.BOF Then
Exit Sub

ELSE
        DoCmd.GoToRecord , , acPrevious
End If
0
 
LVL 4

Expert Comment

by:Clothahump
ID: 18048515
Agreed.  Either put in the Else or change it to


If NOT rst.BOF Then
        DoCmd.GoToRecord , , acPrevious
End If
0
 

Author Comment

by:skennedy10
ID: 18048520
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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 4

Expert Comment

by:dan_vella
ID: 18048567
What is your aim with this? You could just use

DoCmd.GoToRecord , , acPrevious

on its own if navigation is the only purpose
0
 

Author Comment

by:skennedy10
ID: 18048601
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
 
LVL 4

Accepted Solution

by:
dan_vella earned 250 total points
ID: 18048628
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
 

Author Comment

by:skennedy10
ID: 18060396
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question