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
|
Private Sub Cmd_update_base_Click()
'Mise à jour de la base de données
Dim oApp As Object
Dim oWkb As Object
Dim oWSht As Object
Set oApp = CreateObject("Excel.Application")
Set oWkb = oApp.Workbooks.Open("C:\Documents and Settings\PC\Bureau\Modèle")
Set oWSht = oWkb.Worksheets("BDD")
Dim i As String
Dim searchbord As String
Dim res As DAO.Recordset
'Déclarations de toutes les colonnes à importer:
'1 - Colonnes liées à la table "bordereau"
Dim colA As String, colQI As String, ColQJ As String, colQK As String
Dim insbord
'L'import commence à la ligne 5
i = 5
'importation tant que la cellule est différente de ""
While oWSht.Range("A" & i).Value <> ""
'on stocke l'info dans une variable **Données table T_bordereau**
colA = oWSht.Cells(i, 1).Value 'Numéro bordereau
colQI = oWSht.Cells(i, 451).Value 'Surface totale réalisée
ColQJ = oWSht.Cells(i, 452).Value 'Mode de facturation
colQK = oWSht.Cells(i, 453).Value 'Atelier
'on insert pas les doublons
searchbord = "select numero_bordereau from t_bordereau where numero_bordereau = '" & colA & "'"
Set res = CurrentDb.OpenRecordset(searchbord, dbOpenForwardOnly, dbReadOnly)
If Not res.EOF Then
'requète SQL Bordereau
If colA <> "" Then
insbord = "insert into T_Bordereau (numero_bordereau,Surface_totale,Mode_facturation,Nom_atelier) values ("
insbord = insbord & "'" & colA & "',"
insbord = insbord & "'" & colQI & "',"
insbord = insbord & "'" & ColQJ & "',"
insbord = insbord & "'" & colQK & "')"
'Pas de message d'erreur
DoCmd.SetWarnings False
'on exécute la requête
DoCmd.RunSQL insbord
End If
End If
'passage à la ligne suivante
i = i + 1
Wend
'on libère la mémoire
oApp.DisplayAlerts = False
oWkb.Close
oApp.Quit
Set oWSht = Nothing
Set oWkb = Nothing
Set oApp = Nothing
End Sub |
Partager