I have a form where the first input control is the person’s Surname, and the second is the person’s First Name.
I am trying to prevent users from overtyping the Surname if they inadvertently use a current record, rather that the new record.
The following code shows my actions in dealing with Surname control data entry and then moving to the First Name control and then doing a Disable action on the Surname control.
The Before Update checks for New Record and ignores message.
After the record is Updated, the After Update moves to the next control and Disables the Surname control.
I also have the Lost Focus set to act the same way so that the Surname control Disables when it loses the focus after originally being Enabled and selectable.
What I need to do is the have an “Edit Surname” button which will Enable the Surname control and allow the Surname to be changed (when required).
What is the best way to allow the Surname control to be re-Enabled?
BEFORE UPDATE
[Private Sub CSurname_BeforeUpdate(Cancel As Integer)
'If a new record, ignore message, if not - error message
If Me.NewRecord Then
Cancel = False
Else
If MsgBox("You are about to overwrite this Surname -" & Chr(13) & _
"Are you sure you want to do this?" & Chr(13) & Chr(13) & _
"Click YES to overwrite and continue" & Chr(13) & Chr(13) & _
"Click NO to leave original name", _
vbCritical + vbYesNo + vbDefaultButton2, _
"Surname Error") = vbNo Then
Cancel = True
Me.Undo
End If
End If
End Sub]
AFTER UPDATE
[Private Sub CSurname_AfterUpdate()
'Move to First Name field
DoCmd.GoToControl "CFirstName"
'Disable Surname field
Me.CSurname.Enabled = False
End Sub]
LOST FOCUS
[Private Sub CSurname_LostFocus()
'Move to First Name field
DoCmd.GoToControl "CFirstName"
'Disable Surname field
Me.CSurname.Enabled = False
End Sub]
Thanks for any assistance.
Kind Regards
mortonsafari