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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| Function fNomContrôleNull(frm As Form) As String
'Renvoie le nom d'un contrôle dont la valeur est null mais requise.
'Par FRED.G _ developpez.com
Dim ctl As Control
On Error Resume Next
If Not fCtlNullàMaj(frm, frm.ActiveControl, True) Then
For Each ctl In frm.Controls
If fCtlNullàMaj(frm, ctl) Then
With ctl
FormattedMsgBox "Impossible d'exécuter l'opération demandée.@" & _
"Une valeur est requise pour le champ """"" & _
.StatusBarText & """""." & vbCrLf & _
"Vous devez saisir une valeur ou annuler vos modifications en appuyant sur ÉCHAP.@", vbCritical, TA
.SetFocus
If .ControlType = acComboBox Then .Dropdown
fNomContrôleNull = .Name
End With
Exit Function
End If
Next ctl
Else
With frm.ActiveControl
FormattedMsgBox "Impossible d'exécuter l'opération demandée.@" & _
"Une valeur est requise pour le champ """"" & _
.StatusBarText & """""." & vbCrLf & _
"Vous devez saisir une valeur ou annuler vos modifications en appuyant sur ÉCHAP.@", vbCritical, TA
If .ControlType = acComboBox Then .Dropdown
fNomContrôleNull = .Name
End With
End If
Exit Function
' Bloc de gestion d'erreurs ajouté par le complément Commentaire de code et Gestionnaire d'erreurs VBA. NE MODIFIEZ PAS ce bloc de code.
GestionErr:
Select Case Err.Number
'2474 : L'expression entrée requiert que le contrôle se trouve dans la fenêtre active.
'438 : Propriété ou méthode non gérée par cet objet.
Case 2474, 438
Set frm = Nothing
Case Else
MsgBox "Erreur " & Err.Number & " : " & Err.Description, vbCritical, "mdu.fRenvoieContrôleNull"
Set frm = Nothing
End Select
' Fin du bloc de gestion d'erreurs.
End Function
Function fCtlNullàMaj(frm As Form, ctl As Control, Optional Actif As Boolean) As Boolean
'Par FRED.G _ developpez.com
On Error Resume Next
If Actif Then
fCtlNullàMaj = (Len(ctl.Text) = 0) And frm.Recordset.Fields(ctl.ControlSource).Required
Else
fCtlNullàMaj = IsNull(ctl.Value) And frm.Recordset.Fields(ctl.ControlSource).Required
End If
End Function
Function FormattedMsgBox(Prompt As String, _
Optional Buttons As VbMsgBoxStyle = vbOKOnly, _
Optional Title As String = vbNullString, _
Optional HelpFile As Variant, _
Optional Context As Variant) As VbMsgBoxResult
On Error GoTo GestionErr
If IsMissing(HelpFile) Or IsMissing(Context) Then
FormattedMsgBox = Eval("MsgBox(""" & Prompt & """, " & Buttons & ", """ & Title & """)")
Else
FormattedMsgBox = Eval("MsgBox(""" & Prompt & """, " & Buttons & ", """ & Title & """, """ & _
HelpFile & """, " & Context & ")")
End If
Exit Function
' Bloc de gestion d'erreurs ajouté par le complément Commentaire de code et Gestionnaire d'erreurs VBA. NE MODIFIEZ PAS ce bloc de code.
GestionErr:
Select Case Err.Number
Case Else
MsgBox "Erreur " & Err.Number & " : " & Err.Description, vbCritical, "mdu.FormattedMsgBox"
End Select
' Fin du bloc de gestion d'erreurs.
End Function |
Partager