Make a command button conditionally unavailable

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

I have two simple command buttons that navigate back-n-forth between
available records. How can modify the forward button so that if there is
only one record, the button grays out can not be used? Right now, it is
always available, even though there isn't always a second record.

As a heads up, I'm OK with access, but not with coding. If the answer
involves such, please tell me exactly what to do with the code provided.

Thanks!
Joe
 
The easiest answer to this is to use the built-in buttons. However, it can
be done in code. You would check the current record number against the
record count of the form. If they match, you're at the last record. This
could be done in the form's Current event.

If Me.Recordset.AbsolutePosition + 1 = Me.Recordset.RecordCount Then
Me.cmdNextButton.Enabled = False
Else
Me.cmdNextButton.Enabled = True
End If
 
Wayne,

This does make a difference. The next button IS disabled. Only problem is
that it seems to be 'permanently' disabled. Even if this subform has more
than one record available, the button does not become available. Any ideas?

Thanks for your help so far. I'm very excited to see my goal almost reached!
Joe
 
Joe,

The code I listed, if placed in the form's Current event, won't care what
the default setting of the button is (enabled or disabled). Instead the code
will set it as needed for the current position in the form's record set. You
may need to make an exception also for no records (i.e. RecordCount = 0).
 
Wayne,

Forgive me...I'm just a little confused by your response. What exactly does
the code you provided for me do? It is supposed to enable the next button if
the record count is more than one? If so, what am I missing? So far, the
button continues to remain disabled 100% of the time.

And how would the exception you listed look like in the code you provided?

Thanks again for you help. I truly appreciate it.,
Joe
 
Yes, it should enable the button if there is one or more records remaining.
Where have you placed the code? Did you adjust the name that I used for the
actual name of your button? You now mention a subform, where has this code
been placed in relation to the subform? Where is the button located in
relation to the subform?
 
To check for no records or at a new record, just ammend the IF part of the
statement. This will get a little long, the first line should be all on one
line. The newsreader will proabably wrap it due to its length.

If Me.Recordset.AbsolutePosition + 1 = Me.Recordset.RecordCount Or
Me.Recordset.RecordCount = 0 Or Me.NewRecord Then
Me.cmdNextButton.Enabled = False
Else
Me.cmdNextButton.Enabled = True
End If
 
Thanks for the new code. I will update accordingly.

Yes - the code has been placed into the subform properties (double-clicked
the small gray box in upper left corner of form). It was placed in the 'On
Current' line as an 'Event procedure'. The button names in the code you
provided have been changed to work with the names I gave them. The buttons
themselves appear in the detail section of the subform. The entire subform
has then been placed into the detail section of the main form.

Hope this helps,
Joe
 
Friend,

joel-ange sitbon has invited you to join GreenZap and get $50 WebCash to
spend online. Sign up for a FREE GreenZap account and get $50 to spend at
hundreds of the world's premier merchants, many of whom are offering
incredible upfront discounts. Click on the link below to go to GreenZap and
signup! All thanks to joel-ange sitbon.

It's Zappening in the GreenZap Storez.
http://www.greenzap.com/joel1962

If you do not want to receive these emails in the future click the link
below:
http://www.greenzap.com/optout_invite.asp
 
Back
Top