I've got a form with record control buttons (client request) that should be enable/disable acc. to record status. Here's the approach I'm using--please critique if you find a better way or a problem; please borrow if you like it:
In order to make the buttons' status reflect the appropriate options they are enabled/disabled acc. to form status.
A general module has this sub that is common to all forms:
[tt]
Public Sub SetRecordButtons(Frm As Form, SetValue As String)
'On Error Resume Next
Select Case SetValue
Case "NewRecord"
Frm.cmdNew.Enabled = False
Frm.cmdSave.Enabled = False
Frm.cmdCancel.Enabled = False
Frm.cmdDelete.Enabled = False
Case "ExistingRecord"
Frm.cmdNew.Enabled = True
Frm.cmdSave.Enabled = False
Frm.cmdCancel.Enabled = False
Frm.cmdDelete.Enabled = True
Case "DirtyRecord"
Frm.cmdNew.Enabled = False
Frm.cmdSave.Enabled = True
Frm.cmdCancel.Enabled = True
Frm.cmdDelete.Enabled = False
Case "Updated"
Frm.cmdNew.Enabled = True
Frm.cmdSave.Enabled = False
Frm.cmdCancel.Enabled = False
Frm.cmdDelete.Enabled = True
Case Else
End Select
End Sub
[/tt]
In the Form_Current Event (occurs after a Find of existing record, a Delete, or an Insert):
[tt]
Private Sub Form_Current()
On Error Resume Next
If Me.NewRecord Then
'Sub in basCoreRoutines
SetRecordButtons Me, "NewRecord"
Else
'Sub in basCoreRoutines
SetRecordButtons Me, "ExistingRecord"
End If
End Sub
[/tt]
In the Form_AfterUpdate Event (occurs after a Save):
[tt]
'Sub in basCoreRoutines
SetRecordButtons Me, "ExistingRecord"
[/tt]
To capture and respond to any Cancel operation, the following is done in the Form_Timer (every second) event:
[tt]
Private Sub Form_Timer()
On Error Resume Next
If Me.Dirty Then
SetRecordButtons Me, "DirtyRecord"
Else
If Me.NewRecord Then
'Sub in basCoreRoutines
SetRecordButtons Me, "NewRecord"
Else
'Sub in basCoreRoutines
SetRecordButtons Me, "ExistingRecord"
End If
End If
End Sub
[/tt]
* The use of any event associated with the Cancel button itself will fail because the button can't be disabled while it has focus-even the case with "Lost_Focus" event.
Jeff Roberts
Analysis, Design, & Implementation
RenaissanceData.com
In order to make the buttons' status reflect the appropriate options they are enabled/disabled acc. to form status.
A general module has this sub that is common to all forms:
[tt]
Public Sub SetRecordButtons(Frm As Form, SetValue As String)
'On Error Resume Next
Select Case SetValue
Case "NewRecord"
Frm.cmdNew.Enabled = False
Frm.cmdSave.Enabled = False
Frm.cmdCancel.Enabled = False
Frm.cmdDelete.Enabled = False
Case "ExistingRecord"
Frm.cmdNew.Enabled = True
Frm.cmdSave.Enabled = False
Frm.cmdCancel.Enabled = False
Frm.cmdDelete.Enabled = True
Case "DirtyRecord"
Frm.cmdNew.Enabled = False
Frm.cmdSave.Enabled = True
Frm.cmdCancel.Enabled = True
Frm.cmdDelete.Enabled = False
Case "Updated"
Frm.cmdNew.Enabled = True
Frm.cmdSave.Enabled = False
Frm.cmdCancel.Enabled = False
Frm.cmdDelete.Enabled = True
Case Else
End Select
End Sub
[/tt]
In the Form_Current Event (occurs after a Find of existing record, a Delete, or an Insert):
[tt]
Private Sub Form_Current()
On Error Resume Next
If Me.NewRecord Then
'Sub in basCoreRoutines
SetRecordButtons Me, "NewRecord"
Else
'Sub in basCoreRoutines
SetRecordButtons Me, "ExistingRecord"
End If
End Sub
[/tt]
In the Form_AfterUpdate Event (occurs after a Save):
[tt]
'Sub in basCoreRoutines
SetRecordButtons Me, "ExistingRecord"
[/tt]
To capture and respond to any Cancel operation, the following is done in the Form_Timer (every second) event:
[tt]
Private Sub Form_Timer()
On Error Resume Next
If Me.Dirty Then
SetRecordButtons Me, "DirtyRecord"
Else
If Me.NewRecord Then
'Sub in basCoreRoutines
SetRecordButtons Me, "NewRecord"
Else
'Sub in basCoreRoutines
SetRecordButtons Me, "ExistingRecord"
End If
End If
End Sub
[/tt]
* The use of any event associated with the Cancel button itself will fail because the button can't be disabled while it has focus-even the case with "Lost_Focus" event.
Jeff Roberts
Analysis, Design, & Implementation
RenaissanceData.com