Sub Insert()
Application.ScreenUpdating = False
'------------Déclarations des variables------------------
Dim DateJour As Long, Restaurant As Double, Bar As Double, Couverts As Integer, Offerts As Integer
etc...
chemin = ActiveWorkbook.Path
Dim objCommand As ADODB.Command
Dim rsData As ADODB.Recordset
Dim lRecordsAffected As Long
Dim szConnect As String
On Error GoTo ErrorHandler
Sheets("DonneesBordereau").Select
Sheets("DonneesBordereau").Cells(2, 1).Select
DateJour = ActiveCell
Restaurant = ActiveCell.Offset(0, 1)
etc...
szConnect = "Provider=Microsoft.jet.OLEDB.4.0;" & _
"Data Source=" & chemin & "\" & Base & ";" & _
"Mode-Share Exclusive"
If Not FileExists(Base) Then
MsgBox "Le fichier Base.mdb est introuvable !", vbCritical, "Erreur critique !"
GoTo ErrorExit
End If
Set objCommand = New ADODB.Command
objCommand.ActiveConnection = szConnect
objCommand.CommandText = "INSERT INTO Datas(DateJour,Restaurant,Bar,Couverts,Offerts,Cinema,BarMAS,Cigarettes,Animation" & _
",Boule,PbBoule,EntreesBoule,Roulette,PbRoulette,BJ,PbBJ,EntreesJeux,CSG,MAS,PbMAS,EntreesMAS,Orph,Erreurs,DropMAS,DropRoulette,DropBoule" & _
",Comptee,H,F,Glaces,ChqMAS,CBMAS,ChqJeux,CBJeux,Positifs,Negatifs,BouleFerme,JeuxFerme,OrphJeux,OrphBoule,Location,Billeterie,ChequesBar,CBBar" & _
",ChequesResto,CBResto,TicketsResto,OffertsResto,OffertsBar,OffertsBarMAS,Banquet, PMU, PMU_Paris, TITOfin, TITOdebut, Coupons, fdj, ErreursGJ" & _
", RAE, Forfaits_MAS, TITOSexp, PbRAE, BJE)" & _
"VALUES(" & DateJour & "," & Restaurant & "," & Bar & "," & Couverts & "," & Offerts & "," & Cinema & _
"," & BarMAS & "," & Cigarettes & "," & Animation & "," & Boule & "," & PbBoule & "," & EntreesBoule & _
"," & Roulette & "," & PbRoulette & "," & BJ & "," & PbBJ & "," & EntreesJeux & "," & CSG & "," & MAS & _
"," & pbMAS & "," & EntreesMAS & "," & Orph & "," & Erreurs & "," & DropMAS & "," & DropRoulette & "," & _
DropBoule & "," & Comptee & "," & H & "," & F & "," & Glaces & "," & ChqMAS & "," & CBMAS & "," & ChqJeux & "," & _
CBJeux & "," & Positifs & "," & Negatifs & "," & BouleFerme & "," & JeuxFerme & "," & OrphJeux & "," & OrphBoule & "," & Location & "," & _
Billeterie & "," & ChequesBar & "," & CBBar & "," & ChequesResto & "," & CBResto & "," & TicketsResto & "," & OffertsResto & "," & _
OffertsBar & "," & OffertsBarMAS & "," & Banquet & "," & PMU & "," & PMU_Paris & "," & titofin & "," & TITOdebut & "," & coupons & "," & _
FDJ & "," & ErreursGJ & "," & RAE & "," & Forfaits_MAS & "," & TITOSexp & "," & PbRAE & "," & BJE & ");"
objCommand.Execute RecordsAffected:=lRecordsAffected, Options:=adCmdText
PasErreur = 1
If lRecordsAffected <> 1 Then Err.Raise Number:=vbObjectError + 1024, Description:="Erreur d'execution de l'instruction INSERT."
ErrorExit:
Set objCommand = Nothing
Set rsData = Nothing
Exit Sub
ErrorHandler:
MsgBox Err.Description, vbCritical
Resume ErrorExit
Application.ScreenUpdating = True
End Sub