1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| Sub AjouterVente()
Dim rng As Range
Dim Cn As ADODB.Connection
Dim oCm As ADODB.Command
Dim StrDate As Date
Dim StrDesc As String
Dim StrPU As Double
Dim StrQuant As Double
Dim StrTot As Double
Dim StrEtat As String
Dim nLigneRecup As Integer
On Error GoTo ADO_ERROR
Set Cn = New ADODB.Connection
Cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Database.mdb;Persist Security Info=False"
Cn.ConnectionTimeout = 40
Cn.Open
'---------------------------------- Transferts des Ventes ------------------------
For Each rng In Sheets(1).Range("G5:G1000000").SpecialCells(xlCellTypeConstants).Cells
If rng.Value = "Oui" Then
StrDate = CDate(rng.Offset(0, -5).Value)
StrDesc = rng.Offset(0, -4).Value
StrPU = rng.Offset(0, -3).Value
StrQuant = rng.Offset(0, -2).Value
StrTot = rng.Offset(0, -1).Value
StrEtat = rng.Value
Set oCm = New ADODB.Command
oCm.ActiveConnection = Cn
oCm.CommandText = "Insert Into Ventes Values (#" & StrDate & "#,'" & StrDesc & "'," & StrPU & "," & StrQuant & "," & StrTot & ",'" & StrEtat & "')"
oCm.Execute nLigneRecup
End If
Next
'-------------------------------------- Transfert des Factures --------------------------
For Each rng In Sheets(1).Range("O5:O1000000").SpecialCells(xlCellTypeConstants).Cells
If rng.Value = "Oui" Then
StrDate = CDate(rng.Offset(0, -5).Value)
StrDesc = rng.Offset(0, -4).Value
StrPU = rng.Offset(0, -3).Value
StrQuant = rng.Offset(0, -2).Value
StrTot = rng.Offset(0, -1).Value
StrEtat = rng.Value
Set oCm = New ADODB.Command
oCm.ActiveConnection = Cn
oCm.CommandText = "Insert Into Factures Values (#" & StrDate & "#,'" & StrDesc & "'," & StrPU & "," & StrQuant & "," & StrTot & ",'" & StrEtat & "')"
oCm.Execute nLigneRecup
End If
Next
If nLigneRecup = 0 Then
MsgBox "Pas de données à transférer"
End If
If Cn.State <> adStateClosed Then
Cn.Close
End If
Application.StatusBar = False
If Not oCm Is Nothing Then Set oCm = Nothing
If Not Cn Is Nothing Then Set Cn = Nothing
MsgBox "Transfert Términé.", vbInformation
ADO_ERROR:
MsgBox Err.Description
End Sub |
Partager