p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

access thread: I have a small problem....


Message #1 by "Aleksandra" <zabunia@y...> on Thu, 6 Jun 2002 02:08:22
i'm trying to program my "next" adn "Previous" buttons on the form in 
VBA... They have to be Enabled or not depending if i'm at the beginning 
of my data base or the end... does anyone have an idea of how i could do 
it?

I would be very grateful 
Aleksandra
Message #2 by "Amy Wyatt" <amyw@c...> on Thu, 6 Jun 2002 14:02:57
I am assuming you are building your own Next and Previous buttons. If you 
are, you can accomplish what you are trying to do by keeping track of the 
number of records in the recordset (ie. intMaxRecords) then you can 
compare the Forms CurrentRecord property to the intMaxRecords and disable 
Next when CurrentRecord = intMaxRecords and disable Previous if 
CurrentRecord=1. Do this in the Forms OnCurrent Event.

Hope this helps,

Amy



> i'm trying to program my "next" adn "Previous" buttons on the form in 
V> BA... They have to be Enabled or not depending if i'm at the beginning 
o> f my data base or the end... does anyone have an idea of how i could do 
i> t?

> I would be very grateful 
A> leksandra
Message #3 by "Gerald, Rand" <RGerald@u...> on Thu, 6 Jun 2002 09:53:49 -0500
The method for building this set of buttons is described in "Access
Cookbook" by Getz, Litwin, and Baron (Page 78)

Rand E Gerald
Database Specialist
Information Services / Operations
Bah=E1'=ED National Office
1233 Central St.
Evanston IL 60201
(xxx) xxx-xxxx

-----Original Message-----
From: Aleksandra [mailto:zabunia@y...]
Sent: Wednesday, June 05, 2002 9:08 PM
To: Access
Subject: [access] I have a small problem....

i'm trying to program my "next" adn "Previous" buttons on the form in
VBA... They have to be Enabled or not depending if i'm at the beginning
of my data base or the end... does anyone have an idea of how i could 
do
it?

I would be very grateful
Aleksandra
Message #4 by "Randy Cornish" <rlcornish@c...> on Fri, 7 Jun 2002 23:57:22
Assuming you are able to access the recordset, check the .BOF = True or 
the .EOF = True property (if DAO/Jet).

R

> i'm trying to program my "next" adn "Previous" buttons on the form in 
V> BA... They have to be Enabled or not depending if i'm at the beginning 
o> f my data base or the end... does anyone have an idea of how i could 
do 
i> t?

> I would be very grateful 
A> leksandra
Message #5 by "Aleksandra" <zabunia@y...> on Sat, 8 Jun 2002 20:50:07
Thank you all, I kept track of the number of records :)

Aleksandra 
Message #6 by "Leo Scott" <leoscott@c...> on Tue, 11 Jun 2002 15:06:59 -0700
Try this tip I got from Element K journals

********** THE TIP **********

Enhancing custom record navigation buttons (Access 97/2000/2002)

We recently told you how to switch a control's Enabled property by taking
advantage of the fact that it's simply a Boolean value. You can also use
this technique to enhance record navigation buttons created with the Control
Wizard. Although, the Control Wizard makes it easy to add your own
navigation buttons to a form, the buttons don't disable themselves when you
reach the beginning or end of a form's records. Instead, if you click the
Previous button when you're in the first record, Access generates an error.
Similarly, if you're in the last record or a new record and you click the
Next button, Access also generates an error.

To avoid this behavior, you can make these custom navigation buttons
self-disabling; that is, they'll disable and enable themselves as necessary.
To set up the code to do this, open the VBE and select Form from the Object
dropdown list. Then, select Current from the Procedure dropdown list. At the
insertion point, type the following code:

btnPrevious.Enabled = CBool(Me.CurrentRecord - 1)

The CBool function converts all numbers except 0 to -1, or True. So,
btnPrevious remains enabled until the CurrentRecord value equals 1. To
create the self-disabling Next button,
press [Enter] to add a new line to the above procedure, and then type

btnNext.Enabled = Not Me.NewRecord

As you probably know, the NewRecord property returns True when the current
record is a new record, so VBA enables btnNext whenever the current record
isn't a new record. If you don't allow additions in your form, however, you
won't have new records, so instead you'll want to test whether the current
record value is less than the total number of form records. You can set the
button's Enabled property equal to this test, like so:

btnNext.Enabled = (Me.CurrentRecord < Me.RecordsetClone.RecordCount)

Under this expression, whenever the CurrentRecord value is less than the
total record count, the evaluation returns True, enabling the button.
Otherwise, the evaluation returns False, automatically disabling btnNext.


|-----Original Message-----
|From: Aleksandra [mailto:zabunia@y...]
|Sent: Thursday, June 06, 2002 2:08 AM
|To: Access
|Subject: [access] I have a small problem....
|
|
|i'm trying to program my "next" adn "Previous" buttons on the form in
|VBA... They have to be Enabled or not depending if i'm at the beginning
|of my data base or the end... does anyone have an idea of how i could do
|it?
|
|I would be very grateful
|Aleksandra
|


  Return to Index