Macro error code

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

In a form I have created a control button as a macro to
goto prevouis record. If you are at the first record of
the database and select the button to goto prevouis, which
I thought it should goto the last record of the database
at that point. An error displays " End of record Set",
then the second error follows action failed-Halt screen
displays. How can you get the error to stop and the
database to see the last record when you are the first
record and click the goto provouis button?
 
You have hit upon the major problem with macros. You cannot trap errors.
Instead of using macros, I'd recreate the navigations buttons using the
button wizard. It will write code do do this things. (Essentially they are
DoCmd. methods). The nice thing about the button wizard is that it
automatically creates the error trapping code. Then you can trap for the
beginning or end of the recordset and do a different action accordingly.
 
Bob,

It would not be the expected behaviour in any case for a GoToPrevious
button to go to the last record if you are currently on the first.

To get the result you are after, put two GoToRecord actions in your
macro, like this...

Condition: [Forms]![NameOfYourForm].[CurrentRecord]>1
Action: GoToRecord
Record: Previous
Condition: [Forms]![NameOfYourForm].[CurrentRecord]=1
Action: GoToRecord
Record: Last

If you wanted the more usual approach, you would do the second action in
the macro like this...
Condition: [Forms]![NameOfYourForm].[CurrentRecord]=1
Action: MsgBox
Message: Can't go to previous record - you are on the first!
 
Back
Top