Error message if field is empty access
Solved
Loic_7447
Posted messages
32
Registration date
Status
Membre
Last intervention
-
f894009 Posted messages 17417 Registration date Status Membre Last intervention -
f894009 Posted messages 17417 Registration date Status Membre Last intervention -
Hello,
I have a form that serves to add data to a table, using 4 text boxes and a final button.
The form works very well, but I would like it so that if a field is empty when validating the addition, the record is not created and an error message appears.
Here is my code:
I tried to add the following lines:
But nothing works (maybe I didn't put them in the right place or who knows).
Could you help me??
Thanks in advance.
I have a form that serves to add data to a table, using 4 text boxes and a final button.
The form works very well, but I would like it so that if a field is empty when validating the addition, the record is not created and an error message appears.
Here is my code:
Private Sub btn_ajouter_Click()
Set db = CurrentDb
Set rs = db.OpenRecordset("Stock_atelier")
rs.AddNew
rs!Référence = Me.txt_reference
rs!Fournisseur = Me.txt_fournisseur
rs!Quantité = Me.txt_quantité
rs!Type = Me.txt_outil
rs.Update
rs.Close
db.Close
MsgBox "Référence ajoutée avec succès "
txt_reference = ""
txt_fournisseur = ""
txt_quantité = ""
txt_outil = ""
Set rs = Nothing
Set db = Nothing
End Sub
I tried to add the following lines:
If IsNull(Me.txt_reference) Then
MsgBox ("Veuillez renseigner toutes les cases")
ElseIf IsNull(Me.txt_fournisseur) Then
MsgBox ("Veuillez renseigner toutes les cases")
ElseIf IsNull(Me.txt_quantité) Then
MsgBox ("Veuillez renseigner toutes les cases")
ElseIf IsNull(Me.txt_outil) Then
MsgBox ("Veuillez renseigner toutes les cases")
End If
But nothing works (maybe I didn't put them in the right place or who knows).
Could you help me??
Thanks in advance.
Mark your Access request as completed