Solved

BOF and EOF problems

Posted on 2006-11-30
7
391 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Access query 16 61
SUBFORM on ACCESS 2013 8 35
Convert MS Access Excel Routine to Late Binding 6 25
Access 2003 query, remove dupes 17 25
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

734 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