Solved

BOF and EOF problems

Posted on 2006-11-30
7
398 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
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.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

636 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