Disable buttons on last record (1 Viewer)

Ironis

Learning Member...
Local time
Today, 15:43
Joined
Oct 10, 2002
Messages
61
Hi

I'd like to disable some buttons when I'm on the last record.
I made browse buttons, and left the standard browsebuttons away. Now I want the "next" and "Last record" buttons to be disabled when the last record is on screen. Also, I want the "first" and "previous record" buttons to be disabled on the first record.

I also wish to disable my "Undo" and "save" buttons, when nothing is changed, + the "Delete" button when there's an empty record.

I know this is a lot, please anyone help me out!
 

R. Hicks

AWF VIP
Local time
Today, 13:44
Joined
Dec 23, 1999
Messages
619
Go to the link below and download the Navigation Button sample database.
This should help you disable your Next, Last, First, and Previous Bttons.

Navigation Button Sample

HTH
RDH
 

Oldsoftboss

AWF VIP
Local time
Tomorrow, 04:44
Joined
Oct 28, 2001
Messages
2,499
the code I use in the form - current

Me.RecordsetClone.MoveLast
If (Me.RecordsetClone.RecordCount) < 1.5 Then 'There is only one record

PreviousButton.Enabled = False
NextButton.Enabled = False

ElseIf Me.RecordsetClone.RecordCount = Me.CurrentRecord Then 'Your at the last record
PreviousButton.Enabled = True
NextButton.Enabled = False

ElseIf Me.CurrentRecord = 1 Then 'Your at the first record
PreviousButton.Enabled = False
NextButton.Enabled = True

Else 'Your somewhere inbetween
PreviousButton.Enabled = True
NextButton.Enabled = True

end if

HTH
Dave
 
Last edited:

Ironis

Learning Member...
Local time
Today, 15:43
Joined
Oct 10, 2002
Messages
61
I used the code from the tutorial, but I'm getting a type mismatch error. Can't figure out the problem.

I also have a public function, which is used on every button on the form. This one checks wether a few checkboxes are checked, en if they are, the form shows specific subforms. When a checkbox isn't checked, there's another subform or no subvorm visible. This works perfectly, but it might influence the disable button code, but I don't know for sure. If anyone needs the code to help me out, I will place it here.

Tnx for the help so far!

Ironis
 

Ironis

Learning Member...
Local time
Today, 15:43
Joined
Oct 10, 2002
Messages
61
Ok, I got it almost figured
The error I got was from the piece of code which defines the recordclone. That gave the typemismatch.

Now I used both codes (mixed) and it works perfectly.

Now the only little thing left is the following:
When I have a new record, And fill in the first field (txtLastname) it will trigger an after_update event on the txtLastName field. This way, the right buttons will be enabled again. But, the next and last button will also be enabled, but it's the last record. This is still the only problem. I tried some things, but I got only errors, or the code simply got messed up when just browsing the records.

Also, When I use the code on another form, where there's no record yet, The first and previous buttons also appear, I trietr to change the code here on some points, but it seems it doesn't help.

Thanks again for all your help!!
 
Last edited:

Oldsoftboss

AWF VIP
Local time
Tomorrow, 04:44
Joined
Oct 28, 2001
Messages
2,499
How do ou get the new record?
If you get there with the navigation buttons at the bottom of the screen, then the form-current event should take care of it.
If you have a "Add New Record" button just put Nextbutton.enabled = false
then when you go back through the records the 'forms-current event' will re enable the button
Dave
 

Ironis

Learning Member...
Local time
Today, 15:43
Joined
Oct 10, 2002
Messages
61
I disabled the standard record navigation buttons, so I have made my own add record button. The problem is not that I didn't define the code for a new record, but the problem is this: When there is no record, you begin on a new record, and then there should be no buttons enabled. When I have a new record, and there are other records, the prev and first buttons should be enabled. I triet to figure out some code, that when you're on a new record, it will check wether there are no records, or there are records, but somehow this doesn't work..
 

Ironis

Learning Member...
Local time
Today, 15:43
Joined
Oct 10, 2002
Messages
61
OK, now I changed the code, so that when there's a new record, all buttons will be disabled, but they are still enabled...

Here's the code I use
Private Sub Form_Current()
Dim intNewRecord As Integer
On Error GoTo Err_Form_Current

'Define intNewRecord (New Record):
'When PersonCode_ID is Null there is a new record
intNewRecord = IsNull(Me!reservationnumber_ID)

Me.RecordsetClone.MoveLast

'Check if there is null or one record
If (Me.RecordsetClone.RecordCount) < 1.5 Then
'There is only one or no record
'disable all buttons
cmdMoveFirst.Enabled = False
cmdMovePrev.Enabled = False
cmdMoveNext.Enabled = False
cmdMoveLast.Enabled = False
Exit Sub
'Check if you're on a "New Record"
ElseIf intNewRecord Then
'This is a new record
'Enable the first and prev buttons
'Disable the next and last buttons
cmdMoveFirst.Enabled = False
cmdMovePrev.Enabled = False
cmdMoveNext.Enabled = False
cmdMoveLast.Enabled = False
Exit Sub
'Check if this is the last record
ElseIf Me.RecordsetClone.RecordCount = Me.CurrentRecord Then
'This is the last record
'Enable the first and prev buttons
'Disable the next and last buttons
cmdMoveFirst.Enabled = True
cmdMovePrev.Enabled = True
cmdMoveNext.Enabled = False
cmdMoveLast.Enabled = False
'Check if this is the 1st record
ElseIf Me.CurrentRecord = 1 Then
'This is the first record
'Disable the first and prev buttons
'Enable the next and last buttons
cmdMoveFirst.Enabled = False
cmdMovePrev.Enabled = False
cmdMoveNext.Enabled = True
cmdMoveLast.Enabled = True
'None of the above = somewhere in between beginning and end
'Enable all buttons
Else
cmdMoveFirst.Enabled = True
cmdMovePrev.Enabled = True
cmdMoveNext.Enabled = True
cmdMoveLast.Enabled = True
End If

Exit_Form_Current:
Exit Sub

Err_Form_Current:
'Error 3021 means recordset is at "Add new Record"
'Enable <Previous> and <first> buttons
'Disable <Next> and <Last> buttons
If Err = 3021 Then
cmdMoveFirst.Enabled = True
cmdMovePrev.Enabled = True
cmdMoveNext.Enabled = False
cmdMoveLast.Enabled = False
Resume Exit_Form_Current
End If
End Sub

Access thinks that the new record is the last record..
Can anyone help.. tnx

Ironis
 

Users who are viewing this thread

Top Bottom