The problem with that is that, because the control's Enabled property is set
to true in the form's Current event procedure, all a user needs to do to
change a supplier is to navigate back to an existing record. All that's
needed is the following in the form's Current event procedure:
Me.Supplier.Enabled = Me.NewRecord
and in the Form's AfterInsert event procedure:
Me.Supplier.Enabled = False
to cater for a user explicitly saving the record without navigating away
from it. Its still rather inflexible, however, if a user finds that they've
mistakenly entered the wrong supplier. Its not difficult for a reasonably
informed user to edit the row in the table by other means of course, but if
we ignore that possibility, I'd be inclined to require the user to confirm
the saving of the record. The following code is from a form's module is a
simple example of how the use of a command button and confirmation dialogue
to save a record can be forced:
Option Compare Database
Option Explicit
Dim blnSaved As Boolean
Private Sub cmdSave_Click()
Const MESSAGETEXT = "Save record?"
If MsgBox(MESSAGETEXT, vbQuestion + vbYesNo, "Confirm") = vbYes Then
blnSaved = True
On Error Resume Next
RunCommand acCmdSaveRecord
If Err <> 0 Then
blnSaved = False
End If
End If
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not blnSaved Then
Cancel = True
End If
End Sub
Private Sub Form_Current()
blnSaved = False
End Sub
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Const IS_DIRTY = 2169
If DataErr = IS_DIRTY Then
Response = acDataErrContinue
End If
End Sub
Ken Sheridan
Stafford, England