florian50470
XLDnaute Nouveau
Bonjour pouvez vous m'aider j'ai une erreur 1004 sur mon code,normalement il derais ajouter une ligne mais ca ne marche pas.
Le blocage est sur la ligne en jaune -> Set b = b.Offset(0, 1)
Private Sub CommandButton1_Click()
Dim i As Long
Dim j As Long
Dim b As Object
Dim x As Long
Dim y As Long
Dim Prive As Object
Dim Bloc As Object
Dim BDD As Object
Dim Supp As Object
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
If MsgBox("Etes-vous certain de vouloir INSERER ce nouveau Pointage ?", vbYesNo, "Demande de confirmation") = vbYes Then 'condition si oui au message
Sheets("Pointage").Unprotect "INGELIANCECHERBOURG"
If ComboBox2 = "" Then
MsgBox ("Veuillez entrer un numéro de tâche")
Else
If TextBox3 = "" Then
MsgBox ("Veuillez entrer le temps effectuer")
Else
'Blocage = oui
If ComboBox3 = "Oui" Then
'Recherche la coordonnée i (n°ligne)
Set b = Sheets("Pointage").Range("A100")
Do While b.Value <> ComboBox2.Value
Set b = b.Offset(1, 0)
Loop
i = b.Row
'Recherche la coordonnée j (n°colonne)
Set b = Sheets("Pointage").Range("D12")
Do While b.Value <> CDate(TextBox5.Value)
Set b = b.Offset(1, 0)
Loop
j = b.Column
Cells(i, j).Value = CDec(TextBox3.Value) + Cells(i, j).Value
'Blocage = non
Else
Set b = Sheets("Pointage").Range("A15")
Do While b.Value <> ComboBox2.Value
Set b = b.Offset(0, 1)
Loop
i = b.Row
Set b = Sheets("Pointage").Range("D12")
Do While b.Value <> CDate(TextBox5.Value)
Set b = b.Offset(1, 0)
Loop
j = b.Column
Cells(i, j).Value = CDec(TextBox3.Value) + Cells(i, j).Value
End If
End If
End If
'Insère les données sur Data Base
Sheets("Data Base").Unprotect "INGELIANCECHERBOURG"
Set BDD = Sheets("Data Base").Range("C3")
Do While BDD <> ComboBox2.Value
Set BDD = BDD.Offset(1, 0)
Loop
BDD.Offset(0, 16).Value = BDD.Offset(0, 16).Value + TextBox3.Value
Set Supp = Sheets("Data Base").Range("PointageBDD")
Supp.ClearContents
Set BDD = Sheets("Data Base").Range("BC7")
BDD.Value = TextBox4.Value
BDD.Offset(0, 1).Value = ComboBox2.Value
If ComboBox3.Value = "" Then
BDD.Offset(0, 2).Value = "-"
Else
BDD.Offset(0, 2).Value = ComboBox4.Value
End If
BDD.Offset(0, 3).Value = TextBox5.Value
BDD.Offset(0, 4).Value = TextBox3.Value
If ComboBox3.Value = "Oui" Then
BDD.Offset(0, 5).Value = "Blocage"
Else
BDD.Offset(0, 5).Value = "Pointage"
End If
BDD.Offset(0, 6).FormulaLocal = "=RECHERCHEV([@Tache];$C$3:$V$600;10;FAUX)"
BDD.Offset(0, 7).FormulaLocal = "=RECHERCHEV([@Tache];$C$3:$V$600;4;FAUX)"
BDD.Offset(0, 8).FormulaLocal = "=RECHERCHEV([@Tache];$C$3:$V$600;19;FAUX)"
If ComboBox5.Visible = False Then
BDD.Offset(0, 9).Value = "-"
Else
BDD.Offset(0, 9).Value = ComboBox5.Value
End If
'Insère les données dans la Base de Données Access
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & "Data Source=" & ThisWorkbook.Path & "\Base de Données.accdb"
Set rs = New ADODB.Recordset
rs.Open "Pointage", cn, adOpenKeyset, adLockOptimistic, adCmdTable
With rs
.AddNew
.Fields("Po_Nom") = Range("PointageBDD[Nom]").Value
.Fields("Po_Tache") = Range("PointageBDD[Tache]").Value
.Fields("Po_Type de Tache") = Range("PointageBDD[Type de Tache]").Value
.Fields("Po_Date") = Range("PointageBDD[Date]").Value
.Fields("Po_Temps") = Format(Range("PointageBDD[Temps]").Value, "0.00")
.Fields("Po_Type de Pointage") = Range("PointageBDD[Type de Pointage]").Value
.Fields("Po_Type Metier") = Range("PointageBDD[Type Metier]").Value
.Fields("Po_Lot Affecte") = Range("PointageBDD[Lot Affecte]").Value
.Fields("Po_Affaire Affectee") = Range("PointageBDD[Affaire Affectee]").Value
.Fields("Po_N°incidence") = Range("PointageBDD[Numero incidence]").Value
.Update
End With
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
Unload Me
End If
End Sub
Le blocage est sur la ligne en jaune -> Set b = b.Offset(0, 1)
Private Sub CommandButton1_Click()
Dim i As Long
Dim j As Long
Dim b As Object
Dim x As Long
Dim y As Long
Dim Prive As Object
Dim Bloc As Object
Dim BDD As Object
Dim Supp As Object
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
If MsgBox("Etes-vous certain de vouloir INSERER ce nouveau Pointage ?", vbYesNo, "Demande de confirmation") = vbYes Then 'condition si oui au message
Sheets("Pointage").Unprotect "INGELIANCECHERBOURG"
If ComboBox2 = "" Then
MsgBox ("Veuillez entrer un numéro de tâche")
Else
If TextBox3 = "" Then
MsgBox ("Veuillez entrer le temps effectuer")
Else
'Blocage = oui
If ComboBox3 = "Oui" Then
'Recherche la coordonnée i (n°ligne)
Set b = Sheets("Pointage").Range("A100")
Do While b.Value <> ComboBox2.Value
Set b = b.Offset(1, 0)
Loop
i = b.Row
'Recherche la coordonnée j (n°colonne)
Set b = Sheets("Pointage").Range("D12")
Do While b.Value <> CDate(TextBox5.Value)
Set b = b.Offset(1, 0)
Loop
j = b.Column
Cells(i, j).Value = CDec(TextBox3.Value) + Cells(i, j).Value
'Blocage = non
Else
Set b = Sheets("Pointage").Range("A15")
Do While b.Value <> ComboBox2.Value
Set b = b.Offset(0, 1)
Loop
i = b.Row
Set b = Sheets("Pointage").Range("D12")
Do While b.Value <> CDate(TextBox5.Value)
Set b = b.Offset(1, 0)
Loop
j = b.Column
Cells(i, j).Value = CDec(TextBox3.Value) + Cells(i, j).Value
End If
End If
End If
'Insère les données sur Data Base
Sheets("Data Base").Unprotect "INGELIANCECHERBOURG"
Set BDD = Sheets("Data Base").Range("C3")
Do While BDD <> ComboBox2.Value
Set BDD = BDD.Offset(1, 0)
Loop
BDD.Offset(0, 16).Value = BDD.Offset(0, 16).Value + TextBox3.Value
Set Supp = Sheets("Data Base").Range("PointageBDD")
Supp.ClearContents
Set BDD = Sheets("Data Base").Range("BC7")
BDD.Value = TextBox4.Value
BDD.Offset(0, 1).Value = ComboBox2.Value
If ComboBox3.Value = "" Then
BDD.Offset(0, 2).Value = "-"
Else
BDD.Offset(0, 2).Value = ComboBox4.Value
End If
BDD.Offset(0, 3).Value = TextBox5.Value
BDD.Offset(0, 4).Value = TextBox3.Value
If ComboBox3.Value = "Oui" Then
BDD.Offset(0, 5).Value = "Blocage"
Else
BDD.Offset(0, 5).Value = "Pointage"
End If
BDD.Offset(0, 6).FormulaLocal = "=RECHERCHEV([@Tache];$C$3:$V$600;10;FAUX)"
BDD.Offset(0, 7).FormulaLocal = "=RECHERCHEV([@Tache];$C$3:$V$600;4;FAUX)"
BDD.Offset(0, 8).FormulaLocal = "=RECHERCHEV([@Tache];$C$3:$V$600;19;FAUX)"
If ComboBox5.Visible = False Then
BDD.Offset(0, 9).Value = "-"
Else
BDD.Offset(0, 9).Value = ComboBox5.Value
End If
'Insère les données dans la Base de Données Access
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & "Data Source=" & ThisWorkbook.Path & "\Base de Données.accdb"
Set rs = New ADODB.Recordset
rs.Open "Pointage", cn, adOpenKeyset, adLockOptimistic, adCmdTable
With rs
.AddNew
.Fields("Po_Nom") = Range("PointageBDD[Nom]").Value
.Fields("Po_Tache") = Range("PointageBDD[Tache]").Value
.Fields("Po_Type de Tache") = Range("PointageBDD[Type de Tache]").Value
.Fields("Po_Date") = Range("PointageBDD[Date]").Value
.Fields("Po_Temps") = Format(Range("PointageBDD[Temps]").Value, "0.00")
.Fields("Po_Type de Pointage") = Range("PointageBDD[Type de Pointage]").Value
.Fields("Po_Type Metier") = Range("PointageBDD[Type Metier]").Value
.Fields("Po_Lot Affecte") = Range("PointageBDD[Lot Affecte]").Value
.Fields("Po_Affaire Affectee") = Range("PointageBDD[Affaire Affectee]").Value
.Fields("Po_N°incidence") = Range("PointageBDD[Numero incidence]").Value
.Update
End With
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
Unload Me
End If
End Sub