Problème syntaxe suppression

josothy

XLDnaute Junior
bonjour,

J'ai un problème apparement de syntaxe pour un bouton de suppression. J'ai une erreur

With RechNom
.Clear
For i = 1 To 1
Controls("Textbox" & i) = ""
Next i
End With

En faite j'ai renommer mes textbox et je voudrais savoir comment toutes les nommer a la suite dans mon code ?

Bonne journée
 

Excel-lent

XLDnaute Barbatruc
Re : Problème syntaxe suppression

Bonsoir Josothy

Code:
For i = 1 To [COLOR="Blue"][B]15[/B][/COLOR]
    Controls("Textbox" & i)[COLOR="Red"][U].value[/U][/COLOR] = ""
Next i


dans le cas où tu aurais 15 TextBox

Mais cela uniquement dans le cas où dans les propriétés de tes TextBox tu es sur la ligne (Name) :
-> TextBox1 pour ta première TextBox
-> TextBox2 pour ta seconde TextBox
-> ...

Josothy à dit:
En faite j'ai renommer mes textbox et je voudrais savoir comment toutes les nommer a la suite dans mon code ?

Je ne sais pas faire et ne vois pas l'intérêt de renommer des TextBox dans le code!

Bon WE.
 

Bebere

XLDnaute Barbatruc
Re : Problème syntaxe suppression

bonjour Josothy

si rechnom est un userform

With RechNom
For i = 1 To x ' x étant le nbre de textbox
.Controls("Textbox" & i) = "" 'vide ne pas oublier le point
.Controls("Textbox" & i) .name="Nom que tu veux donner" & i
Next i
End With

ou bien

Dim Ctrl As Control

'Boucle pour tous les contrôles de UserForm
For Each Ctrl In UserForm1.Controls
If TypeOf Ctrl Is MSForms.TextBox Then Ctrl.Value = VbNullString'vide,VbNullString pour éviter " "
Next
Set Ctrl = Nothing

si problème tu nous en dis plus ou tu mets un fichier

à bientôt
 

josothy

XLDnaute Junior
Re : Problème syntaxe suppression

merci de ton aide. malheureusement j'ai toujours la même erreur.

Je renomme mes textbox parce que c'est un gros fichier excel que je fais avec déja une dizaine de feuille et pareille de userform alors c'est pour essayer de m'y retrouver un peu dans tout ça.

Je viens de voir ton message bebere j'essaye tout de suite
 

Bebere

XLDnaute Barbatruc
Re : Problème syntaxe suppression

bonjour Excellent
Josothy
tu remplaces With RechNom par With UserForm1 où le nom que tu lui as donné

à mettre dans un Module,sert pour tous les userform
pour l'appel dans chaque userform : EffaceTextBox Me
Me fait référence à l'userform d'où vient l'appel

Public Sub EffaceTextBox(ByRef UForm As UserForm)
Dim Ctrl As Control
'Boucle pour tout les contrôle de UForm
For Each Ctrl In UForm.Controls
If TypeOf Ctrl Is MSForms.TextBox Then Ctrl.Value = VbNullString
Next
Set Ctrl = Nothing
End Sub

pour l'appel : Call EffaceTextBox(Me, "TextBox2", "TextBox4")

Public Sub EffaceTextBox(ByRef UForm As UserForm, ParamArray ExceptTextBoxes())
Dim Ctrl As Control, i As Long, bModif As Boolean
'Boucle pour tout les contrôle de UForm
For Each Ctrl In UForm.Controls
bModif = True
If TypeOf Ctrl Is MSForms.TextBox Then
For i = LBound(ExceptTextBoxes) To UBound(ExceptTextBoxes)
If Ctrl.Name = ExceptTextBoxes(i) Then
bModif = False
Exit For
End If
Next i
If bModif Then Ctrl.Value = vbNullString
End If
Next
Set Ctrl = Nothing
End Sub

à bientôt
 

josothy

XLDnaute Junior
Re : Problème syntaxe suppression

Rebonjour

Je crois que je suis trop nul en faite. et le pire c'est que je peux meme pas mettre mon fichier il est trop gros meme ziper. Je met mon code au cas ou quelqu'un pourrait m'aider.

Private Sub Supprimer_Click()
Dim Nom As String
Dim cell As Range
Dim msg As Integer
Dim i As Byte
Nom = RechNom.Value
msg = MsgBox("Vous allez supprimer :" & RechNom.Value & "", vbYesNo + vbInformation, "ATTENTION")

If msg = vbYes Then
With Sheets("Données")
For Each cell In .Range("A2:A" & Range("A2").End(xlDown).Row)
If (cell.Value) & " " & cell.Offset(0, 1) = Nom Then
cell.EntireRow.Delete
Exit For
End If
Next cell
End With

Dim Ctrl As Control
For Each Ctrl In UserForm1.Controls
If TypeOf Ctrl Is MSForms.TextBox Then Ctrl.Value = vbNullString 'vide,VbNullString pour éviter " "
Next
Set Ctrl = Nothing
End If

With UserForm2
For i = 1 To x ' x étant le nbre de textbox
Controls("Textbox" & i).Value = ""
Next i
End With

Call EffaceTextBox(Me, "Adresse", "Code", "Ville", "Telfixe", "Teltrav", "Telport", "Ndevis1", "Ndevis2", "Ndevis3", "Ndevis4", "Ndevis5", "Ndevis6", "Ncommande1", "Ncommande2", "Ncommande3", "Ncommande4", "Ncommande5", "Ncommande6", "Cd1", "Cd2", "Cd3", "Cd4", "Cd5", "Cd6", "Cc1", "Cc2", "Cc3", "Cc4", "Cc5", "Cc6")

End Sub
 

josothy

XLDnaute Junior
Re : Problème syntaxe suppression

Nouveau problème sur la feuille de code de ma userform j'ai des conflits parce que j'ai deux combobox1_change et deux userform_inizialize je met le code (fichier trop gros)il faudrait intégrer le tiens (qui marche très bien tout seul)

Private Sub Retour_click()

Worksheets("Acceuil").Visible = True
Worksheets("Données").Visible = False

Unload Me

End Sub

Private Sub RechNom_Change()
Dim It As Long
EffaceTout
If RechNom.ListIndex = -1 Then Exit Sub
It = RechNom.ListIndex + 2
With Sheets("Données")
Adresse = .Range("B" & It)
Code = .Range("C" & It)
Ville = .Range("D" & It)
Ndevis1 = .Range("E" & It)
Ndevis2 = .Range("F" & It)
Ndevis3 = .Range("G" & It)
Ndevis4 = .Range("H" & It)
Ndevis5 = .Range("I" & It)
Ndevis6 = .Range("J" & It)
Ncommande1 = .Range("K" & It)
Ncommande2 = .Range("L" & It)
Ncommande3 = .Range("M" & It)
Ncommande4 = .Range("N" & It)
Ncommande5 = .Range("O" & It)
Ncommande6 = .Range("P" & It)
Telfixe = .Range("Q" & It)
Teltrav = .Range("R" & It)
Telport = .Range("S" & It)
Cd1 = .Range("T" & It)
Cd2 = .Range("U" & It)
Cd3 = .Range("V" & It)
Cd4 = .Range("W" & It)
Cd5 = .Range("X" & It)
Cd6 = .Range("Y" & It)
Cc1 = .Range("Z" & It)
Cc2 = .Range("AA" & It)
Cc3 = .Range("AB" & It)
Cc4 = .Range("AC" & It)
Cc5 = .Range("AD" & It)
Cc6 = .Range("AE" & It)
End With

End Sub

Private Sub UserForm_Initialize()
Dim Derlign As Long
With Worksheets("Données")
Derlign = .Range("A65000").End(xlUp).Row
.Range("B1:C" & Derlign).Sort Key1:=.Range("B1"), Order1:=xlAscending, Header:=xlGuess
RechNom.List = .Range("A2:AE" & Derlign).Value
End With
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then Cancel = True

End Sub
Private Sub Modifier_click()

Dim It As Long
If RechNom.ListIndex = -1 Then Exit Sub
It = RechNom.ListIndex + 2
With Sheets("Données")
.Range("B" & It) = Adresse
.Range("C" & It) = Code
.Range("D" & It) = Ville
.Range("E" & It) = Ndevis1
.Range("F" & It) = Ndevis2
.Range("G" & It) = Ndevis3
.Range("H" & It) = Ndevis4
.Range("I" & It) = Ndevis5
.Range("J" & It) = Ndevis6
.Range("K" & It) = Ncommande1
.Range("L" & It) = Ncommande2
.Range("M" & It) = Ncommande3
.Range("N" & It) = Ncommande4
.Range("O" & It) = Ncommande5
.Range("P" & It) = Ncommande6
.Range("Q" & It) = Telfixe
.Range("R" & It) = Teltrav
.Range("S" & It) = Telport
.Range("T" & It) = Cd1
.Range("U" & It) = Cd2
.Range("V" & It) = Cd3
.Range("W" & It) = Cd4
.Range("X" & It) = Cd5
.Range("Y" & It) = Cd6
.Range("Z" & It) = Cc1
.Range("AA" & It) = Cc2
.Range("AB" & It) = Cc3
.Range("AC" & It) = Cc4
.Range("AD" & It) = Cc5
.Range("AE" & It) = Cc6
End With

MsgBox ("Les données ont bien été modifiées")

End Sub

Private Sub Cd1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If (Dir(Cd1.Text) <> "" And Cd1.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cd1.Text
End Sub

Private Sub Cd2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If (Dir(Cd2.Text) <> "" And Cd2.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cd2.Text
End Sub
Private Sub Cd3_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If (Dir(Cd3.Text) <> "" And Cd3.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cd3.Text
End Sub
Private Sub Cd4_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If (Dir(Cd4.Text) <> "" And Cd4.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cd4.Text
End Sub
Private Sub Cd5_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If (Dir(Cd5.Text) <> "" And Cd5.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cd5.Text
End Sub
Private Sub Cd6_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If (Dir(Cd6.Text) <> "" And Cd6.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cd6.Text
End Sub
Private Sub Cc1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If (Dir(Cc1.Text) <> "" And Cc1.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cc1.Text
End Sub
Private Sub Cc2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If (Dir(Cc2.Text) <> "" And Cc2.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cc2.Text
End Sub
Private Sub Cc3_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If (Dir(Cc3.Text) <> "" And Cc3.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cc3.Text
End Sub
Private Sub Cc4_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If (Dir(Cc4.Text) <> "" And Cc4.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cc4.Text
End Sub
Private Sub Cc5_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If (Dir(Cc5.Text) <> "" And Cc5.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cc5.Text
End Sub
Private Sub Cc6_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If (Dir(Cc6.Text) <> "" And Cc6.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cc6.Text
End Sub
Private Sub RechNom_Change()
Dim C As Byte, L As Long, Cell As Range
'pas de sélection termine
If RechNom.ListIndex = -1 Then Exit Sub

With Sheets("Données").Range("A1:A" & Range("A2").End(xlDown).Row)
Set Cell = .Find(RechNom.Value)
If Not Cell Is Nothing Then
L = Cell.Row
For C = 1 To 3
Me.Controls("Textbox" & C).Value = .Cells(L, C + 1).Value
Next C
End If
End With

End Sub

Private Sub Supprimer_Click()

Dim Nom As String, VarReponse As String
Dim Cell As Range
Dim msg As Integer
Dim i As Byte


VarReponse = MsgBox("Effacer Ce Client?", vbYesNo, "Alerte")
If VarReponse = vbNo Then Exit Sub

With Sheets("Données").Range("A1:A" & Range("A2").End(xlDown).Row)
Set Cell = .Find(RechNom.Value)
If Not Cell Is Nothing Then
Rows(Cell.Row).Delete
End If
End With


'efface toutes les textbox
Call EffaceTextBox(Me)
'la ou les textbox en paramètre ne sont pas effacées
' Call EffaceTextBox1(Me, "TextBox2", "TextBox4")

End Sub

Private Sub UserForm_Initialize()

With Sheets("Données")
Set rng = .Range("A2:A" & .Range("A65536").End(xlUp).Row)
Me.RechNom.List = rng.Value
End With

End Sub
 

Bebere

XLDnaute Barbatruc
Re : Problème syntaxe suppression

Josothy
le fichier est amélioré,tu as ajouter,modifier,supprime et quitter(boutons)
tu peux ajouter des colonnes
tu as une fonction qui donne l'index de colonne
les textbox ont pour nom les entêtes de colonnes
n'oublie pas que le contenu des contrôles c'est du texte
exemple
pour les dates écrire cells(1,1)=cdate(textbox1)
pour les chiffres écrire cells(1,1)=cdbl(textbox1)
à bientôt
 

Pièces jointes

  • essaiJosothy.zip
    22.3 KB · Affichages: 31

ROGER2327

XLDnaute Barbatruc
Re : Problème syntaxe suppression

Bonjour à tous
En l'absence de classeur, difficile de vérifier ce code.
j'ai des conflits parce que j'ai deux combobox1_change et deux userform_inizialize
Je ne vois pas ça dans le code : j'y vois deux procédures de nom RechNom_Change et deux nommées UserForm_Initialize. C'est au moins une de trop à chaque fois.
est placé ce code ? Est-il placé dans le même conteneur ?
Je vois aussi l'appel d'une procédure EffaceTout qui n'existe pas dans le code et pas mal de variables non déclarées...
Pour moi, tout cela est trop imprécis. Désolé de ne pouvoir donner un coup de main...
Toutefois, comme j'ai pris le temps de regarder, je mets le code dans une forme plus lisible (ça ne prend pas beaucoup de temps, mais ça peut en faire gagner à ceux qui en donnent) :
Code:
Private Sub Retour_click()
    Worksheets("Acceuil").Visible = True
    Worksheets("Données").Visible = False
    Unload Me
End Sub

Private Sub RechNom_Change()
Dim It As Long
    EffaceTout
    If RechNom.ListIndex = -1 Then Exit Sub
    It = RechNom.ListIndex + 2
    With Sheets("Données")
        Adresse = .Range("B" & It)
        Code = .Range("C" & It)
        Ville = .Range("D" & It)
        Ndevis1 = .Range("E" & It)
        Ndevis2 = .Range("F" & It)
        Ndevis3 = .Range("G" & It)
        Ndevis4 = .Range("H" & It)
        Ndevis5 = .Range("I" & It)
        Ndevis6 = .Range("J" & It)
        Ncommande1 = .Range("K" & It)
        Ncommande2 = .Range("L" & It)
        Ncommande3 = .Range("M" & It)
        Ncommande4 = .Range("N" & It)
        Ncommande5 = .Range("O" & It)
        Ncommande6 = .Range("P" & It)
        Telfixe = .Range("Q" & It)
        Teltrav = .Range("R" & It)
        Telport = .Range("S" & It)
        Cd1 = .Range("T" & It)
        Cd2 = .Range("U" & It)
        Cd3 = .Range("V" & It)
        Cd4 = .Range("W" & It)
        Cd5 = .Range("X" & It)
        Cd6 = .Range("Y" & It)
        Cc1 = .Range("Z" & It)
        Cc2 = .Range("AA" & It)
        Cc3 = .Range("AB" & It)
        Cc4 = .Range("AC" & It)
        Cc5 = .Range("AD" & It)
        Cc6 = .Range("AE" & It)
    End With
End Sub

Private Sub UserForm_Initialize()
Dim Derlign As Long
    With Worksheets("Données")
        Derlign = .Range("A65000").End(xlUp).Row
        .Range("B1:C" & Derlign).Sort Key1:=.Range("B1"), Order1:=xlAscending, Header:=xlGuess
        RechNom.List = .Range("A2:AE" & Derlign).Value
    End With
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    If CloseMode = 0 Then Cancel = True
End Sub

Private Sub Modifier_click()
Dim It As Long
    If RechNom.ListIndex = -1 Then Exit Sub
    It = RechNom.ListIndex + 2
    With Sheets("Données")
        .Range("B" & It) = Adresse
        .Range("C" & It) = Code
        .Range("D" & It) = Ville
        .Range("E" & It) = Ndevis1
        .Range("F" & It) = Ndevis2
        .Range("G" & It) = Ndevis3
        .Range("H" & It) = Ndevis4
        .Range("I" & It) = Ndevis5
        .Range("J" & It) = Ndevis6
        .Range("K" & It) = Ncommande1
        .Range("L" & It) = Ncommande2
        .Range("M" & It) = Ncommande3
        .Range("N" & It) = Ncommande4
        .Range("O" & It) = Ncommande5
        .Range("P" & It) = Ncommande6
        .Range("Q" & It) = Telfixe
        .Range("R" & It) = Teltrav
        .Range("S" & It) = Telport
        .Range("T" & It) = Cd1
        .Range("U" & It) = Cd2
        .Range("V" & It) = Cd3
        .Range("W" & It) = Cd4
        .Range("X" & It) = Cd5
        .Range("Y" & It) = Cd6
        .Range("Z" & It) = Cc1
        .Range("AA" & It) = Cc2
        .Range("AB" & It) = Cc3
        .Range("AC" & It) = Cc4
        .Range("AD" & It) = Cc5
        .Range("AE" & It) = Cc6
    End With
    MsgBox ("Les données ont bien été modifiées")
End Sub

Private Sub Cd1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    If (Dir(Cd1.Text) <> "" And Cd1.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cd1.Text
End Sub

Private Sub Cd2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    If (Dir(Cd2.Text) <> "" And Cd2.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cd2.Text
End Sub

Private Sub Cd3_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    If (Dir(Cd3.Text) <> "" And Cd3.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cd3.Text
End Sub

Private Sub Cd4_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    If (Dir(Cd4.Text) <> "" And Cd4.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cd4.Text
End Sub

Private Sub Cd5_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    If (Dir(Cd5.Text) <> "" And Cd5.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cd5.Text
End Sub

Private Sub Cd6_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    If (Dir(Cd6.Text) <> "" And Cd6.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cd6.Text
End Sub

Private Sub Cc1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    If (Dir(Cc1.Text) <> "" And Cc1.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cc1.Text
End Sub

Private Sub Cc2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    If (Dir(Cc2.Text) <> "" And Cc2.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cc2.Text
End Sub

Private Sub Cc3_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    If (Dir(Cc3.Text) <> "" And Cc3.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cc3.Text
End Sub

Private Sub Cc4_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    If (Dir(Cc4.Text) <> "" And Cc4.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cc4.Text
End Sub

Private Sub Cc5_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    If (Dir(Cc5.Text) <> "" And Cc5.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cc5.Text
End Sub

Private Sub Cc6_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    If (Dir(Cc6.Text) <> "" And Cc6.Text <> vbNullString) Then Application.Workbooks.Open Filename:=Cc6.Text
End Sub

Private Sub RechNom_Change()
Dim C As Byte, L As Long, Cell As Range
'pas de sélection termine
    If RechNom.ListIndex = -1 Then Exit Sub
    With Sheets("Données").Range("A1:A" & Range("A2").End(xlDown).Row)
        Set Cell = .Find(RechNom.Value)
        If Not Cell Is Nothing Then
            L = Cell.Row
            For C = 1 To 3
            Me.Controls("Textbox" & C).Value = .Cells(L, C + 1).Value
            Next C
        End If
    End With
End Sub

Private Sub Supprimer_Click()
Dim Nom As String, VarReponse As String
Dim Cell As Range
Dim msg As Integer
Dim i As Byte
    VarReponse = MsgBox("Effacer Ce Client?", vbYesNo, "Alerte")
    If VarReponse = vbNo Then Exit Sub
    With Sheets("Données").Range("A1:A" & Range("A2").End(xlDown).Row)
        Set Cell = .Find(RechNom.Value)
        If Not Cell Is Nothing Then
            Rows(Cell.Row).Delete
        End If
    End With
'efface toutes les textbox
    Call EffaceTextBox(Me)
'la ou les textbox en paramètre ne sont pas effacées
' Call EffaceTextBox1(Me, "TextBox2", "TextBox4")
End Sub

Private Sub UserForm_Initialize()
    With Sheets("Données")
        Set rng = .Range("A2:A" & .Range("A65536").End(xlUp).Row)
        Me.RechNom.List = rng.Value
    End With
End Sub
Bon courage pour la suite !
ROGER2327
 

josothy

XLDnaute Junior
Re : Problème syntaxe suppression

J'ai décidé de tout reprendre a zéro pour repartir sur de bonne base avec comme base de travail tout ce que tu m'as donné bébére et tout marche. merci vraiment. merci aussi aux autre qui m'ont aidé aussi.
 

Discussions similaires

Statistiques des forums

Discussions
312 677
Messages
2 090 813
Membres
104 672
dernier inscrit
robaine salah