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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
Sub CommandButton1_Click()
'Fonction de connexion
'Tableaux de donnees
Dim champs(50) As String
Dim Apport(50) As Integer
Dim prod_gaz_sec(50) As Integer
Dim cons_fuel_gaz(50) As Integer
Dim GPL_vap(50) As Integer
Dim gaz_inj(50) As Integer
Dim gaz_torche(50) As Integer
Dim gaz_expdGR(50) As Integer
Dim gaz_expd(50) As Integer
Dim gaz_reserve(50) As Integer
Dim sql_stat As String
Dim x As String
x = "C:\Program Files\Common Files\system\ado\msado15.dll"
ThisWorkbook.VBProject.References.AddFromFile x
Dim y As String
y = "C:\Program Files\Common Files\system\ado\msador15.dll"
ThisWorkbook.VBProject.References.AddFromFile y
Dim z As String
z = "C:\Program Files\Common Files\system\ado\msadox.dll"
ThisWorkbook.VBProject.References.AddFromFile z
'Variables pour la connexion Oracle
Dim cnOra As ADODB.Connection
Dim rsOra As ADODB.Recordset
Dim db_name As String
db_name = Worksheets(3).Cells(1, 2).Value
userORA = Worksheets(3).Cells(2, 2).Value
pwdORA = Worksheets(3).Cells(3, 2).Value
'' Etablir la connexion
Set cnOra = New ADODB.Connection
Set rsOra = New ADODB.Recordset
cnOra.Open "DSN=" + db_name + ";UID=" + userORA + ";PWD=" & pwdORA + ";"
rsOra.CursorLocation = adUseServer
'---- Récuperer le nombre de lignes -------------'
rsOra.Open "select count(*) from prod_gaz", cnOra, adOpenForwardOnly
j = rsOra![count(*)]
rsOra.MoveNext
rsOra.Close
'------------------------------------------------'
''--Champs
sql_stat = Worksheets(3).Cells(5, 2).Value
rsOra.Open sql_stat, cnOra, adOpenForwardOnly
i = 0
While Not rsOra.EOF
champs(i) = rsOra![champs]
rsOra.MoveNext
i = i + 1
Wend
rsOra.Close
'-- Apport
sql_stat = Worksheets(3).Cells(6, 2).Value
rsOra.Open sql_stat, cnOra, adOpenForwardOnly
i = 0
While Not rsOra.EOF
Apport(i) = rsOra![Apport]
rsOra.MoveNext
i = i + 1
Wend
rsOra.Close
'-- Prod gaz
sql_stat = Worksheets(3).Cells(7, 2).Value
rsOra.Open sql_stat, cnOra, adOpenForwardOnly
i = 0
While Not rsOra.EOF
prod_gaz_sec(i) = rsOra![prod_gaz]
rsOra.MoveNext
i = i + 1
Wend
rsOra.Close
'-- Cons fuel gaz
sql_stat = Worksheets(3).Cells(8, 2).Value
rsOra.Open sql_stat, cnOra, adOpenForwardOnly
i = 0
While Not rsOra.EOF
cons_fuel_gaz(i) = rsOra![cons]
rsOra.MoveNext
i = i + 1
Wend
rsOra.Close
'-- GPL vap
sql_stat = Worksheets(3).Cells(9, 2).Value
rsOra.Open sql_stat, cnOra, adOpenForwardOnly
i = 0
While Not rsOra.EOF
GPL_vap(i) = rsOra![GPL_vap]
rsOra.MoveNext
i = i + 1
Wend
rsOra.Close
'-- Gaz inj
sql_stat = Worksheets(3).Cells(10, 2).Value
rsOra.Open sql_stat, cnOra, adOpenForwardOnly
i = 0
While Not rsOra.EOF
gaz_inj(i) = rsOra![gaz_inj]
rsOra.MoveNext
i = i + 1
Wend
rsOra.Close
'-- Gaz torche
sql_stat = Worksheets(3).Cells(11, 2).Value
rsOra.Open sql_stat, cnOra, adOpenForwardOnly
i = 0
While Not rsOra.EOF
gaz_torche(i) = rsOra![gaz_torche]
rsOra.MoveNext
i = i + 1
Wend
rsOra.Close
'-- Expedition GR1
sql_stat = Worksheets(3).Cells(12, 2).Value
rsOra.Open sql_stat, cnOra, adOpenForwardOnly
i = 0
While Not rsOra.EOF
gaz_expdGR(i) = rsOra![expd_GR1]
rsOra.MoveNext
i = i + 1
Wend
rsOra.Close
'-- Expedition
sql_stat = Worksheets(3).Cells(13, 2).Value
rsOra.Open sql_stat, cnOra, adOpenForwardOnly
i = 0
While Not rsOra.EOF
gaz_expd(i) = rsOra![expd]
rsOra.MoveNext
i = i + 1
Wend
rsOra.Close
'-- Reserve
sql_stat = Worksheets(3).Cells(14, 2).Value
rsOra.Open sql_stat, cnOra, adOpenForwardOnly
i = 0
While Not rsOra.EOF
gaz_reserve(i) = rsOra![reserve]
rsOra.MoveNext
i = i + 1
Wend
rsOra.Close
'------------------- Remplir les tableau Excel par les données de la BD --------------'
For k = 0 To j - 1
l = 9
Worksheets(1).Cells(l + k, 1) = champs(k)
Worksheets(1).Cells(l + k, 2) = Apport(k)
Worksheets(1).Cells(l + k, 4) = cons_fuel_gaz(k)
Worksheets(1).Cells(l + k, 5) = GPL_vap(k)
Worksheets(1).Cells(l + k, 6) = gaz_inj(k)
Worksheets(1).Cells(l + k, 7) = gaz_torche(k)
If Not k = j - 1 Then
Cells(16 + k, 1).Select
Selection.EntireRow.Insert
End If
Next k
End Sub |
Partager