enable/disable buttons

redblaze

Registered User.
Local time
Today, 16:13
Joined
Jan 12, 2002
Messages
54
does anybody know how i can disable a button when i am viewing the first and last record... i have record changers: previous record and next record buttons. i want the previous button to be disabled if i am on the first record because there are no records before the first one. thanks for your help.
 
create a new moduel and put in the following code. Rename the code or your buttons to fit the function.

Public Function DisableEnable(frm As Form)
'To call the function set the form's OnCurrent
'property to =DisableEndable(Form)
Dim rstClone As Recordset
'Create a clone of the form's recordset to
'move around in without affecting the form's
'recordset
Set rstClone = frm.RecordsetClone
'Determine if the current record is the '
'new reocrd and if it is, disable the Next
'and New Buttons and the exit.
If frm.NewRecord Then
frm!cmdFirst.Enabled = True
frm!cmdNext.Enabled = False
frm!cmdPrevious.Enabled = True
frm!cmdLast.Enabled = True
frm!cmdNew.Enabled = False
Exit Function
End If
'If the current record is not the new record
'enable the new button
frm!cmdNew.Enabled = True
'If there are no records, disable all
'other buttons
If rstClone.RecordCount = 0 Then
frm!cmdFirst.Enabled = False
frm!cmdNext.Enabled = False
frm!cmdPrevious.Enabled = False
frm!cmdLast.Enabled = False
Else
'Synchroninze the current record in the clone
'to be the same as the current record displayed
'in the form
rstClone.Bookmark = frm.Bookmark
'Move to the previous record in the clone,
'if the clone's BOF is True, the form must be
'at the first record so disable the first and
'Previous buttons, otherwise the form is not
'at the first record so enable the First and
'Previous buttons.
rstClone.MovePrevious
If rstClone.BOF Then
frm!cmdFirst.Enabled = False
frm!cmdPrevious.Enabled = False
Else
frm!cmdFirst.Enabled = True
frm!cmdPrevious.Enabled = True
End If
'Resynchronize the current record in the clone
'to be the same as the current record displayed
'in the form.
rstClone.Bookmark = frm.Bookmark
'move to the next record in the clone,
'if the clone's EOF is True, the form must be
'at the last record so disable the next and
'last buttons, otherwise the form is not
'at the first record so enable the next and
'last buttons.
rstClone.MoveNext
If rstClone.EOF Then
frm!cmdNext.Enabled = False
frm!cmdLast.Enabled = False
Else
frm!cmdNext.Enabled = True
frm!cmdLast.Enabled = True
End If
End If
End Function

Then on your forms oncurrent put in =disableenable([form]).

Make sure all the buttons name match the code.

Good Luck.
 

Users who are viewing this thread

Back
Top Bottom