Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean) If TextBox1.Text = vbNullString Then Call MsgBox("Veuillez entrer un nom", vbCritical Or vbOKOnly, "Erreur de saisie") Cancel = True End If End Sub
Private ret As Integer Private Sub CommandButton1_Click() If Not ret = vbCancel Then MsgBox "d'accord, alors " ' ====>>> remplace par tes instructions à exécuter si tout est OK End If End Sub Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean) If TextBox1.Text = "" Then ret = MsgBox("ici ton message d'alerte", vbOKCancel) If ret <> vbCancel Then Cancel True Else ret 999 End If End Sub
If tb_nom="" then Do tb_nom=Inputbox("veuillez entrer un nom?") loop until tb_nom<>"" end if
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionSeul petit bemol, si l'utilisateur ne met pas le focus sur le textBox en question et valide son formulaire, alors il n'y aura pas de message d'erreur
Private Sub TextBox1_Change() If TextBox1.Text = "" Then CommandButton1.Enabled = False CommandButton1.Caption = "textbox à compléter" Else CommandButton1.Enabled = True CommandButton1.Caption = "valider" End If End Sub
Private Type remplies T1 As String T2 As String T3 As String End Type Private toto As remplies Private Sub TextBox1_Change() toto.T1 = Left(Trim(TextBox1.Text), 1) verifions End Sub Private Sub TextBox2_Change() toto.T2 = Left(Trim(TextBox2.Text), 1) verifions End Sub Private Sub TextBox3_Change() toto.T3 = Left(Trim(TextBox3.Text), 1) verifions End Sub Private Sub verifions() CommandButton1.Enabled Len(toto.T1 & toto.T2 & toto.T3) 3 End Sub