Hide button on Input form

  • Thread starter Thread starter Steve via AccessMonster.com
  • Start date Start date
S

Steve via AccessMonster.com

have four command buttons set up on my input form: NEXT | PREVIOUS | FIRST |
LAST - below is an example of the click event code for the Next button - the
user gets error messages if they are on the last record and they then click
"NEXT" or if they are on the first record and they click on the "PREVIOUS"
button. I want to modify my code to hide the "NEXT" button in the event the
last record is being displayed on the screen, and also hide the PREVIOUS
button if they are on the first record. The latter event is not such a
problem, because they just get a harmless message - but sometimes they can be
on the last record, click next and it will try to add a record because there
are some default values set up in my text boxes.

Code:
------------------------------------------------------------------------------
 
Mmmm... easy Previous command button...

Behind the button.

If Me.CurrentRecord = 1 Then
cmdPrevious.enabled = false
Else
docmd.gotorecord, , acprevious
End If

I'd personally turn off "Additions" on the Forms Data tab properties to stop
unnecessary new records being created.

The only other thing that comes to mind is to include a Count function... as
the total number of records will be altering constantly and can't be hard
coded.

Let me know if you're not completely satisfied :)
 
Bin,
Thanks so much - you gave me some great ideas - it never occured to me you
could add records only via a click event

But what did you mean by <<The only other thing that comes to mind is to
include a Count function... as
the total number of records will be altering constantly and can't be hard
coded.>>

I didn't understand the significance of that statement.

Thanks for all your help,

Steve
 
I tried your code - when I'm on the first record, and click the Previous
button, it says : "You can't go to the specfied record"

Steve
 
Sorry... I'm too general...

Ensure you've got the IF statement... and the ELSE statement.

You have to have the docmd.gotorecord, , acprevious inside the else part of
the code... and anything else you're doing on the button.

Otherwise it'll disable the button but then carry on with the code... simply
disabling the button stops you pressing it, the code is only triggered by the
button not dependent on it.

You need to think about re-enabling the previous button when you move to a
record past 1.... on the Next button add

cmdPrevious.enabled = true

If the buttons already enabled nothing happens, if its been turned off it'll
be re-enabled.

Hope it works, it looks like an IF statement issue.

Regards
 
<<You have to have the docmd.gotorecord, , acprevious inside the else part of
the code... and anything else you're doing on the button.>>

I'm confused - it already is inside the IF THEN ELSE statement - I'm not
doing anything else on the button

sorry... I appreciate you trying to help

Steve
 
Last reply for today...

If the button disables... then simply go to the error part of the button's
sub and delete.

msgbox err.description

Leave it blank... It works without this for me... but who knows Microsoft.
You may be getting confirmation of the error despite your error handling IF
statement.

Sorry.
 
Thank you !

bin_leigh said:
Last reply for today...

If the button disables... then simply go to the error part of the button's
sub and delete.

msgbox err.description

Leave it blank... It works without this for me... but who knows Microsoft.
You may be getting confirmation of the error despite your error handling IF
statement.

Sorry.
 
Back
Top