Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
' This procedure checks to see if the data on the form has
' changed. If the data has changed, the procedure prompts the
' user to continue with the save operation or to cancel it. Then
' the action that triggered the BeforeUpdate event is completed.
Dim Ctl As Control
On Error GoTo Err_BeforeUpdate
' The Dirty property is True if the record has been changed.
If Me.Dirty Then
' Prompt to confirm the save operation.
If MsgBox("Do you want to save?", vbYesNo + vbQuestion, "Save Record") = vbNo Then
Me.Undo
Else
For Each Ctrl In Me.Controls
If Ctrl.Tag = "*" And IsNull(Ctrl) Then
MsgBox "A required Field has not been filled."
Cancel = True
Ctrl.SetFocus
Exit For
End If
Next Ctrl
End If
End If
Exit_BeforeUpdate:
Exit Sub
Err_BeforeUpdate:
MsgBox Err.Number & " " & Err.Description
Resume Exit_BeforeUpdate
End Sub
Hi,
THis code avoids a form being closed if a required field (with tag "*") is not filled. How can I expand it to fields on a subform?
Another "issue", how can I personalize the error messages :
1) Can't save record at this time ... (required fields in my table)
2) Multicolumn index causes an error message "Ca't save because of duplicate value in primary key, index ...
My user's do not know nor care about keys and indexes.
"This record already exist !"
thanks
Last edited: