1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| Private Sub CommandSave_Click()
Dim ctl As Control
If MyFormDataIsCorrect(strTargetFieldName, strTargetFieldCaption) = False Then
MsgBox strTargetFieldCaption & " doit contenir une valeur !", vbExclamation
Set ctl = Me.Controls(strTargetFieldName)
ctl.SetFocus
Else
MsgBox "C'est bon, merci !"
DoCmd.Close acForm, Me.Name
End If
Set ctl = Nothing
End Sub
Private Function MyFormDataIsCorrect(ByRef strTargetFieldName As String, ByRef strTargetFieldCaption As String) As Boolean
On Error GoTo L_ErrMyFormDataIsCorrect
If isbull(Me.Matricule) Then
If IsNull(Me.Nom) Then
[....]
Else
strTargetFieldName = "Nom": strTargetFieldCaption = "le nom du quidam"
Err.Raise 94
End If
Else
strTargetFieldName = "Matricule": strTargetFieldCaption = "le Matricule"
Err.Raise 94
End If
MyFormDataIsCorrect = True
On Error GoTo 0
L_ExMyFormDataIsCorrect:
Exit Function
L_ErrMyFormDataIsCorrect:
MyFormDataIsCorrect = False
Resume L_ExMyFormDataIsCorrect
End Function |
Partager