Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Effacer dans une TextBox

1 réponse
Avatar
blackboy
Bonjour à tous et surtout à Michel qui m'a déjà bien aidé.
Je souhaiterais mettre à CommmandButton4 la fonction pour effacer le contenu
des TextBox de mon UserForm afin de pouvoir lancer une recherche dans TextBox2
De même, comment modifier le nom 'UserForm1' dans la boite de dialogue.
Merci, code complet ci-dessous

Option Explicit
Private Code As String

Private Sub CommandButton1_Click() ' Go
If TextBox2 = "" Then GoTo 1
Dim x As Long
x = nRow(ActiveSheet, 2, TextBox2, True)
If x Then
TextBox1 = ActiveSheet.Cells(x, 1)
TextBox3 = ActiveSheet.Cells(x, 3)
TextBox4 = ActiveSheet.Cells(x, 4)
Else
MsgBox "Le code " & TextBox2 & " n'existe pas dans la base de données !", 64
End If
1: TextBox2.SetFocus
End Sub

Private Function nRow&(sh As Worksheet, ByVal Col As Byte, What As Variant,
Whole As Boolean)
Dim W As Range
Set W = sh.Columns(Col).Find(What, LookAt:=IIf(Whole, 1, 2))
If Not W Is Nothing Then nRow = W.Row
End Function

Private Sub CommandButton3_Click() ' Sortie
Unload UserForm1
End Sub

Private Sub CommandButton4_Click()

End Sub

Private Sub TextBox2_Change()
End Sub

Private Sub TextBox4_Change()
End Sub

1 réponse

Avatar
Patrick Fredin
Bonjour,

Voici pour effacer le contenu des TextBox :

TextBox1 = ""
TextBox2 = ""
...

ou (c'est la même chose mais on voit ici précisément la propriété qui est
modifiée) :

TextBox1.Text = ""
TextBox2.Text = ""
...

Pour modifier le nom 'UserForm1', dans la fenêtre VBA, tu vas dans les
propriétés de l'objet 'UserForm1' et tu changes son nom (propriété (Name)).
En générale, la convention est de faire commencer le nom d'un UserForm par
'frm', par exemple 'frmRecherche'.

Cordialement.

--
Patrick

"blackboy" wrote in message
news:
Bonjour à tous et surtout à Michel qui m'a déjà bien aidé.
Je souhaiterais mettre à CommmandButton4 la fonction pour effacer le
contenu
des TextBox de mon UserForm afin de pouvoir lancer une recherche dans
TextBox2
De même, comment modifier le nom 'UserForm1' dans la boite de dialogue.
Merci, code complet ci-dessous

Option Explicit
Private Code As String

Private Sub CommandButton1_Click() ' Go
If TextBox2 = "" Then GoTo 1
Dim x As Long
x = nRow(ActiveSheet, 2, TextBox2, True)
If x Then
TextBox1 = ActiveSheet.Cells(x, 1)
TextBox3 = ActiveSheet.Cells(x, 3)
TextBox4 = ActiveSheet.Cells(x, 4)
Else
MsgBox "Le code " & TextBox2 & " n'existe pas dans la base de données !",
64
End If
1: TextBox2.SetFocus
End Sub

Private Function nRow&(sh As Worksheet, ByVal Col As Byte, What As
Variant,
Whole As Boolean)
Dim W As Range
Set W = sh.Columns(Col).Find(What, LookAt:=IIf(Whole, 1, 2))
If Not W Is Nothing Then nRow = W.Row
End Function

Private Sub CommandButton3_Click() ' Sortie
Unload UserForm1
End Sub

Private Sub CommandButton4_Click()

End Sub

Private Sub TextBox2_Change()
End Sub

Private Sub TextBox4_Change()
End Sub