atc
XLDnaute Junior
Bonjour forum
J’ai un userform pour base de données j’aimerais pouvoir inserer un text provenant d’aun fichier format txt (bloc note) dans la Textbox2 j’ai essayé pas mal de modification mais le systeme me renvoi une erreur d’excution 1004
Private Sub CmdAjouter_Click()
Dim CTRL As Control 'Variable pour la collection des controls
Dim L As Integer 'Variable pour connaitre le numéro de derniere ligne vide
Dim X As Integer, i As Integer 'Variables pour faire la boucle de checking de Duplication
Dim Response As Byte
Dim Match As Byte
'ici une boucle sur tous les controls, si un est vide on sort et on set le focus dessus
For Each CTRL In Me.Controls
If ComboBox1 = '' Or TextBox1 = '' Or TextBox2 = '' Or ComboBox2 = '' Or TextBox3 = '' Or TextBox4 = '' Then
MsgBox 'Donnée Incomplete', vbCritical: Exit Sub
End If
Next CTRL
L = WS.Range('A65536').End(xlUp).Row + 1 ' On identifie la dernière ligne vide en partant du bas
'ici un Control de Duplication
For X = 2 To L
If ComboBox1 = WS.Range('A' & X) Then
Match = Match + 1: i = X
End If
Next X
'Si il y a Duplication on demande en montrant les détails de la Duplication
If Match > 0 Then
Response = MsgBox('Duplication trouvée dans la Database pour : ' & ComboBox1 & vbCrLf & _
'Reg : ' & vbTab & vbTab & WS.Cells(i, 1) & vbCrLf & _
'Appareil : ' & vbTab & vbTab & WS.Cells(i, 2) & vbCrLf & _
'Trajet : ' & vbTab & vbTab & WS.Cells(i, 3) & vbCrLf & _
'Rsfta : ' & vbTab & WS.Cells(i, 4) & vbCrLf & _
'Recu_le : ' & vbShortDate & vbShortDate & WS.Cells(i, 5) & vbCrLf & _
'Validite : ' & vbTab & vbTab & WS.Cells(i, 6) & vbCrLf & _
'Statut : ' & vbTab & vbTab & WS.Cells(i, 7) & vbCrLf & _
'Voulez-Vous Valider ces données ?', vbQuestion + vbOKCancel, T & ' Duplication ' & ComboBox1)
If Response = 1 Then
GoTo Suite 'On suit le déroulement si réponse OK
Else: GoTo Fin 'Sinon On sort
End If
End If
Suite:
'ici avec la Feuille on va faire :
With WS
.Range('A' & L) = ComboBox1 ' On écrit dans chaque colonne les valeurs des différents controls
.Range('B' & L) = TextBox1 ' Idem
.Range('C' & L) = TextBox2 ' Idem
.Range('D' & L) = ComboBox2 ' Idem
.Range('E' & L) = TextBox3 ' Idem
.Range('F' & L) = TextBox4 ' Idem
End With
Ini 'On lance la réinitialisation du UserForm (Macro en haut du Module)
Fin:
End Sub
J’ai un userform pour base de données j’aimerais pouvoir inserer un text provenant d’aun fichier format txt (bloc note) dans la Textbox2 j’ai essayé pas mal de modification mais le systeme me renvoi une erreur d’excution 1004
Private Sub CmdAjouter_Click()
Dim CTRL As Control 'Variable pour la collection des controls
Dim L As Integer 'Variable pour connaitre le numéro de derniere ligne vide
Dim X As Integer, i As Integer 'Variables pour faire la boucle de checking de Duplication
Dim Response As Byte
Dim Match As Byte
'ici une boucle sur tous les controls, si un est vide on sort et on set le focus dessus
For Each CTRL In Me.Controls
If ComboBox1 = '' Or TextBox1 = '' Or TextBox2 = '' Or ComboBox2 = '' Or TextBox3 = '' Or TextBox4 = '' Then
MsgBox 'Donnée Incomplete', vbCritical: Exit Sub
End If
Next CTRL
L = WS.Range('A65536').End(xlUp).Row + 1 ' On identifie la dernière ligne vide en partant du bas
'ici un Control de Duplication
For X = 2 To L
If ComboBox1 = WS.Range('A' & X) Then
Match = Match + 1: i = X
End If
Next X
'Si il y a Duplication on demande en montrant les détails de la Duplication
If Match > 0 Then
Response = MsgBox('Duplication trouvée dans la Database pour : ' & ComboBox1 & vbCrLf & _
'Reg : ' & vbTab & vbTab & WS.Cells(i, 1) & vbCrLf & _
'Appareil : ' & vbTab & vbTab & WS.Cells(i, 2) & vbCrLf & _
'Trajet : ' & vbTab & vbTab & WS.Cells(i, 3) & vbCrLf & _
'Rsfta : ' & vbTab & WS.Cells(i, 4) & vbCrLf & _
'Recu_le : ' & vbShortDate & vbShortDate & WS.Cells(i, 5) & vbCrLf & _
'Validite : ' & vbTab & vbTab & WS.Cells(i, 6) & vbCrLf & _
'Statut : ' & vbTab & vbTab & WS.Cells(i, 7) & vbCrLf & _
'Voulez-Vous Valider ces données ?', vbQuestion + vbOKCancel, T & ' Duplication ' & ComboBox1)
If Response = 1 Then
GoTo Suite 'On suit le déroulement si réponse OK
Else: GoTo Fin 'Sinon On sort
End If
End If
Suite:
'ici avec la Feuille on va faire :
With WS
.Range('A' & L) = ComboBox1 ' On écrit dans chaque colonne les valeurs des différents controls
.Range('B' & L) = TextBox1 ' Idem
.Range('C' & L) = TextBox2 ' Idem
.Range('D' & L) = ComboBox2 ' Idem
.Range('E' & L) = TextBox3 ' Idem
.Range('F' & L) = TextBox4 ' Idem
End With
Ini 'On lance la réinitialisation du UserForm (Macro en haut du Module)
Fin:
End Sub