PDA

View Full Version : [SOLVED:] Previous records button



wj8801
02-25-2007, 09:55 PM
Hi,

Im using a button in a form to go the 1st record to a previous one as there is no previous record (been im on the 1st one) it gives me an error how to i trap this error?

Carl A
02-26-2007, 06:50 AM
If you have the Controls Wizard selected when you add a button to a form it will prompt you as to what function you want the button to perform. Once you select the desired option the Controls Wizard will add the procedure for you complete with error checking. Also Read the online help there are examples for error trapping there.

OBP
02-26-2007, 07:14 AM
To prevent the "You can't go to the selected record" message being displayed you can "Disable" the Previous Button when on the first record.
In the Form's "On Current" event precedure place the following code.


Dim rs As Object
Set rs = Me.Recordset.Clone
rs.Bookmark = Me.Bookmark
rs.MovePrevious
If rs.BOF Then
Command66.Enabled = False
rs.MoveFirst
End If
rs.Close

You will need to change the Command66 to whatever Command button number you are using for the "Previous" move.

wj8801
02-26-2007, 09:50 AM
Thanks problem solved.

Cosmos75
03-02-2007, 05:28 PM
I've got an example of enabling and disabling navigation buttons here (http://www.accessdb.info/content/category/3/68/42/).

It also shows how to display your own "Record X of Y" on the form when not using the built-in navigation (i.e. the one at the bottom of the form).

Hope this helps!
:)