Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Automatiser des exports vers access

3 réponses
Avatar
stanislasRB
Bonjour,
Je souhaite exporter des données d'un classeur xl vers une base access par
vba, sans avoir à ouvrir cette base. Je dispose d'office2003, je suis d'un
niveau correct en vba, mais je ne maitrise absolument pas les echanges entre
applications, et je ne trouve pas de solution dans l'aide.
merci par avance,

3 réponses

Avatar
Philippe
Bonjour Stanislas,

je te laisse te débrouiller avec le code de mon module :

Sache juste que :

- je créee d'abord des fonctions pour vérifier que le fichier excel est
correct
- que la remontée ne va pas pourrir mes tables access (doublons, erreurs, ...)

Enfin, pour comprendre, dans ma base access, deux tables t'intéressent :
- NDF (table des entetes de notes de frais)
- LNDF (table des lignes de notes de frais)

Donc relation de 1 à plusieurs entre NDF et LNDF

Ben bon courage, j'en été à ton point il y a deux mois et je m'en suis sorti
grace au site http://access.developpez.com/faq/ et
http://www.info-3000.com/vbvba/vbainteractionaccess.php principalement.


Astuce : si comme moi tu n'est pas le roi du SQL, tu peux les créer sous
access pour récupérer le bon code émulé (ca, ca va faire gueuler des puristes
à mon avis !!!)

Autre astuce : pour que le code fonctionne, n'oublie pas de cocher les
références ADO, DAO, ou autres sinon tu auras une erreur

Aller, ne te decouraqge surtout pas, c'est pas dur meme si inbuvable au
premier abord.

Philippe.



Function FICHIER_NDF_OK() As Boolean

'1- Vérification bon fichier

'2- Vérification cases remplies

'3- Vérification doublon

'4- Verification paramétrage compte

Application.Calculation = xlCalculationAutomatic

FICHIER_NDF_OK = True

'1- Vérification bon fichier
If ActiveWorkbook.ActiveSheet.Cells(6, 2).Value <> "Version 1.08" Then
Response = MsgBox("Il ne s'agit pas d'un bon fichier ou d'une bonne
version!" & Chr(13) & Chr(13) & "Le programme va s'arrêter.", vbOKOnly +
vbExclamation, "ATTENTION", "", 1000)
FICHIER_NDF_OK = False
Exit Function
End If

'2- Vérifier le décalage des lignes ou des colonnes
If ActiveWorkbook.ActiveSheet.Cells(732, 65).Value <> "MONSIGNET" Then
Response = MsgBox("Des lignes ou des colonnes ont été effacées !" &
Chr(13) & Chr(13) & "Le programme va s'arrêter.", vbOKOnly + vbExclamation,
"ATTENTION", "", 1000)
FICHIER_NDF_OK = False
Exit Function
End If

'3-A Vérification cases remplies

For i = 11 To 16
If ActiveWorkbook.ActiveSheet.Cells(i, 3).Value = "" Then
Response = MsgBox("La cellule qui va être sélectionnée est vide
!" & Chr(13) & Chr(13) & "Le programme va s'arrêter.", vbOKOnly +
vbExclamation, "ATTENTION", "", 1000)
ActiveWorkbook.ActiveSheet.Cells(i, 3).Select
FICHIER_NDF_OK = False
Exit Function
End If
Next
If ActiveWorkbook.ActiveSheet.Cells(11, 5).Value = "" Or
ActiveWorkbook.ActiveSheet.Cells(12, 5).Value = "" Then
Response = MsgBox("La cellule qui va être sélectionnée est vide !" &
Chr(13) & Chr(13) & "Le programme va s'arrêter.", vbOKOnly + vbExclamation,
"ATTENTION", "", 1000)
Range(ActiveWorkbook.ActiveSheet.Cells(5, 5),
ActiveWorkbook.ActiveSheet.Cells(6, 5)).Select
FICHIER_NDF_OK = False
Exit Function
End If

For i = 16 To 25

If ActiveWorkbook.ActiveSheet.Cells(i, 24).Value <> 0 Then
For J = 3 To 6
If ActiveWorkbook.ActiveSheet.Cells(i, J).Value = "" Then
Response = MsgBox("La cellule qui va être sélectionnée
est vide !" & Chr(13) & Chr(13) & "Le programme va s'arrêter.", vbOKOnly +
vbExclamation, "ATTENTION", "", 1000)
ActiveWorkbook.ActiveSheet.Cells(i, J).Select
FICHIER_NDF_OK = False
Exit Function
End If
Next
End If
Next
'3-B Vérification que ce sont bien de chiffres
For i = 16 To 25

If ActiveWorkbook.ActiveSheet.Cells(i, 24).Value <> 0 Then
For J = 8 To 21
If ActiveWorkbook.ActiveSheet.Cells(i, J).Value <> "" Then
If Not IsNumeric(ActiveWorkbook.ActiveSheet.Cells(i,
J).Value) Then
Response = MsgBox("La cellule qui va être
sélectionnée est non numérique !" & Chr(13) & Chr(13) & "Le programme va
s'arrêter.", vbOKOnly + vbExclamation, "ATTENTION", "", 1000)
ActiveWorkbook.ActiveSheet.Cells(i, J).Select
FICHIER_NDF_OK = False
Exit Function
End If
End If
Next
End If
Next

End Function

Function DOUBLON_NDF_OK() As Boolean

DOUBLON_NDF_OK = True
MONACRO = ActiveWorkbook.ActiveSheet.Cells(13, 3).Value
MASEMAINE = ActiveWorkbook.ActiveSheet.Cells(12, 5).Value
MONANNEE = ActiveWorkbook.ActiveSheet.Cells(11, 5).Value



Set BaseSource = DBEngine.Workspaces(0).OpenDatabase("G:Mes
DocumentsTotoAdministratif.mdb")

MySql = "SELECT NDF.ACRO, NDF.SEMAINE, NDF.ANNEE FROM NDF WHERE
(((NDF.ACRO)=""" & MONACRO & """) AND ((NDF.SEMAINE)=" & MASEMAINE & ") AND
((NDF.ANNEE)=" & MONANNEE & "));"
'Mysql = "Select VERIF_ACRO.ACRO From VERIF_ACRO;"

Debug.Print MySql
Set Temp = BaseSource.CreateQueryDef("", MySql)
Set MASELECTION = Temp.OpenRecordset()

If MASELECTION.RecordCount <> 0 Then
DOUBLON_NDF_OK = False
End If

MASELECTION.Close
Temp.Close
Set Temp = Nothing
BaseSource.Close
Set BaseSource = Nothing

End Function

Function COMPTE_PRESENT_NDF_OK() As Boolean

COMPTE_PRESENT_NDF_OK = True
MONACRO = ActiveWorkbook.ActiveSheet.Cells(13, 3).Value

Set BaseSource = DBEngine.Workspaces(0).OpenDatabase("G:Mes
DocumentsTotoAdministratif.mdb")

MySql = "SELECT TOTOS.ACR FROM TOTOS WHERE (((TOTOS.ACR)=""" & MONACRO &
"""));"

Debug.Print MySql
Set Temp = BaseSource.CreateQueryDef("", MySql)
Set MASELECTION = Temp.OpenRecordset()

If MASELECTION.RecordCount = 0 Then
COMPTE_PRESENT_NDF_OK = False
End If

MASELECTION.Close
Temp.Close
Set Temp = Nothing
BaseSource.Close
Set BaseSource = Nothing

End Function


Function COMPTE_PARAMETRE_NDF_OK() As Boolean

COMPTE_PARAMETRE_NDF_OK = True
MONACRO = ActiveWorkbook.ActiveSheet.Cells(13, 3).Value

Set BaseSource = DBEngine.Workspaces(0).OpenDatabase("G:Mes
DocumentsTotoAdministratif.mdb")

MySql = "SELECT TOTOS.ACR, TOTOS.COMPTE FROM TOTOS WHERE
(((TOTOS.ACR)=""" & MONACRO & """) AND ((TOTOS.COMPTE)<>""""));"

Debug.Print MySql
Set Temp = BaseSource.CreateQueryDef("", MySql)
Set MASELECTION = Temp.OpenRecordset()

If MASELECTION.RecordCount = 0 Then
COMPTE_PARAMETRE_NDF_OK = False
End If

MASELECTION.Close
Temp.Close
Set Temp = Nothing
BaseSource.Close
Set BaseSource = Nothing

End Function


Sub REMONTER_NDF()

Dim BaseSource As Database
Dim QueryMag As QueryDef
Dim rstNDF, rstLNDF As Variant
Dim Nom_Magasin, Ville, commercial As String
Dim i As Long

'1- VERIFICATION FICHIER
If FICHIER_NDF_OK = False Then Exit Sub

'2-VERIFICATION NOTE DEJA MONTEE
Rep = vbYes
If DOUBLON_NDF_OK = False Then
Rep = MsgBox("Une note de frais similaire a déjà été montée.
Voulez-vous continuer ?", vbYesNo)
End If
If Rep = vbNo Then
Exit Sub
End If

'3-VERIFICATION COMPTE PRESENT
If COMPTE_PRESENT_NDF_OK = False Then
MsgBox "Le compte n'est pas présent dans la base. La note de frais ne
sera pas montée !"
Exit Sub
End If

'4-VERIFICATION COMPTE PARAMETRE
If COMPTE_PARAMETRE_NDF_OK = False Then
MsgBox "Le compte n'est pas paramétré. La note de frais ne sera pas
montée !"
Exit Sub
End If


'5-DEBUT DE LA REMONTEE

Set BaseSource = DBEngine.Workspaces(0).OpenDatabase("G:Mes
DocumentsTotoAdministratif.mdb")
Set rstNDF = BaseSource.OpenRecordset("NDF", adOpenDynamic,
adLockOptimistic)


If rstNDF.RecordCount = 0 Then

NOUVELID = 1

Else

rstNDF.MoveFirst
MAXID = 0
i = 1
While Not rstNDF.EOF
If rstNDF("ID") > MAXID Then MAXID = rstNDF("ID")
rstNDF.MoveNext
Wend
NOUVELID = MAXID + 1

End If

MONNOM = Cells(11, 3).Value
MONPRENOM = Cells(12, 3).Value
MONACRO = Cells(13, 3).Value
MONEQUIPE = Cells(14, 4).Value
MONANNEE = Cells(11, 5).Value
MASEMAINE = Cells(12, 5).Value
MONPAIEMENT = Cells(15, 3).Value
MADATEREMISE = Cells(16, 3).Value
MONMONTANT = Cells(22, 24).Value

rstNDF.AddNew
rstNDF("ID") = NOUVELID
rstNDF("NOM") = MONNOM
rstNDF("PRENOM") = MONPRENOM
rstNDF("ACRO") = MONACRO
rstNDF("EQUIPE") = MONEQUIPE
rstNDF("ANNEE") = MONANNEE
rstNDF("SEMAINE") = MASEMAINE
rstNDF("PAIEMENT") = MONPAIEMENT
rstNDF("DATE_REMISE") = MADATEREMISE
rstNDF("DATE_REMONTEE") = Date
rstNDF("STATUT") = 1
rstNDF.Update
rstNDF.Close

Set rstNDF = Nothing


'------------------------------------------------------------------------------------------

Set rstLNDF = BaseSource.OpenRecordset("LIGNESNDF", adOpenDynamic,
adLockOptimistic)

If rstLNDF.RecordCount = 0 Then

LNOUVELID = 1

Else

rstLNDF.MoveFirst
MAXID = 0
i = 1
While Not rstLNDF.EOF
If rstLNDF("ID") > MAXID Then MAXID = rstLNDF("ID")
rstLNDF.MoveNext
Wend
LNOUVELID = MAXID + 1

End If


For i = 1 To 7
If Cells(18 + i, 23).Value <> 0 Then

MADATE = Cells(18 + i, 2).Value

MONCLIENT = Cells(18 + i, 3).Value
If IsEmpty(MONCLIENT) Then MONCLIENT = ""

MAVILLE = Cells(18 + i, 4).Value
If IsEmpty(MAVILLE) Then MAVILLE = ""

MAREGION = Cells(18 + i, 23).Value
If IsEmpty(MAREGION) Then MAREGION = ""

MONNBREPERS = Cells(18 + i, 6).Value
If IsEmpty(MAREGION) Then MAREGION = 0

MONPDJ196 = Cells(18 + i, 8).Value
If IsEmpty(MONPDJ196) Then MONPDJ196 = 0

MONPDJ55 = Cells(18 + i, 9).Value
If IsEmpty(MONPDJ55) Then MONPDJ55 = 0

MONPDJETR = Cells(18 + i, 10).Value
If IsEmpty(MONPDJETR) Then MONPDJETR = 0

MONREPAS196 = Cells(18 + i, 11).Value
If IsEmpty(MONREPAS196) Then MONREPAS196 = 0

MONREPAS55 = Cells(18 + i, 12).Value
If IsEmpty(MONREPAS55) Then MONREPAS55 = 0

MONREPASETR = Cells(18 + i, 13).Value
If IsEmpty(MONREPASETR) Then MONREPASETR = 0

MONHOTEL = Cells(18 + i, 14).Value
If IsEmpty(MONHOTEL) Then MONHOTEL = 0

MONPARKING = Cells(18 + i, 15).Value
If IsEmpty(MONPARKING) Then MONPARKING = 0

MONPARKINGETR = Cells(18 + i, 16).Value
If IsEmpty(MONPARKINGETR) Then MONPARKINGETR = 0

MONGASOIL100 = Cells(18 + i, 17).Value
If IsEmpty(MONGASOIL100) Then MONGASOIL100 = 0

MONGASOIL80 = Cells(18 + i, 18).Value
If IsEmpty(MONGASOIL80) Then MONGASOIL80 = 0

MONFUELETR = Cells(18 + i, 19).Value
If IsEmpty(MONFUELETR) Then MONFUELETR = 0

MONPEAGE = Cells(18 + i, 20).Value
If IsEmpty(MONPEAGE) Then MONPEAGE = 0

MONPEAGEETR = Cells(18 + i, 21).Value
If IsEmpty(MONPEAGEETR) Then MONPEAGEETR = 0


rstLNDF.AddNew
rstLNDF("ID") = LNOUVELID
rstLNDF("DATE") = MADATE
rstLNDF("ID_NDF") = NOUVELID
rstLNDF("CLIENT") = MONCLIENT
rstLNDF("VILLE") = MAVILLE
rstLNDF("REGION") = MAREGION
rstLNDF("NBRE PERS") = MONNBREPERS
rstLNDF("PDJ196") = MONPDJ196
rstLNDF("PDJ55") = MONPDJ55
rstLNDF("PDJETR") = MONPDJETR
rstLNDF("REPAS196") = MONREPAS196
rstLNDF("REPAS55") = MONREPAS55
rstLNDF("REPASETR") = MONREPASETR
rstLNDF("PARKING") = MONPARKING
rstLNDF("PARKINGETR") = MONPARKINGETR
rstLNDF("HOTEL") = MONHOTEL
rstLNDF("GASOIL100") = MONGASOIL100
rstLNDF("GASOIL80") = MONGASOIL80
rstLNDF("FUELETR") = MONFUELETR
rstLNDF("PEAGE") = MONPEAGE
rstLNDF("PEAGEETR") = MONPEAGEETR

rstLNDF.Update
LNOUVELID = LNOUVELID + 1
End If
Next

rstLNDF.Close
Set rstNDF = Nothing
BaseSource.Close
Set BaseSource = Nothing
Response = MsgBox("La note de frais est bien montée dans le
système", vbOKOnly + vbInformation, "NDF Remontée", "", 1000)

End Sub












Bonjour,
Je souhaite exporter des données d'un classeur xl vers une base access par
vba, sans avoir à ouvrir cette base. Je dispose d'office2003, je suis d'un
niveau correct en vba, mais je ne maitrise absolument pas les echanges entre
applications, et je ne trouve pas de solution dans l'aide.
merci par avance,


Avatar
stanislasRB
Merci beaucoup, Philippe. Je ne peux pas encore t'affirmer que c'est
exactement ce qu'il me fallait, je vais d'abord aller acheter de
l'aspirine...En tout cas, c'est très clair et très commenté, bravo, c'est une
bonne leçon pour moi.
merci encore.


Bonjour Stanislas,

je te laisse te débrouiller avec le code de mon module :

Sache juste que :

- je créee d'abord des fonctions pour vérifier que le fichier excel est
correct
- que la remontée ne va pas pourrir mes tables access (doublons, erreurs, ...)

Enfin, pour comprendre, dans ma base access, deux tables t'intéressent :
- NDF (table des entetes de notes de frais)
- LNDF (table des lignes de notes de frais)

Donc relation de 1 à plusieurs entre NDF et LNDF

Ben bon courage, j'en été à ton point il y a deux mois et je m'en suis sorti
grace au site http://access.developpez.com/faq/ et
http://www.info-3000.com/vbvba/vbainteractionaccess.php principalement.


Astuce : si comme moi tu n'est pas le roi du SQL, tu peux les créer sous
access pour récupérer le bon code émulé (ca, ca va faire gueuler des puristes
à mon avis !!!)

Autre astuce : pour que le code fonctionne, n'oublie pas de cocher les
références ADO, DAO, ou autres sinon tu auras une erreur

Aller, ne te decouraqge surtout pas, c'est pas dur meme si inbuvable au
premier abord.

Philippe.



Function FICHIER_NDF_OK() As Boolean

'1- Vérification bon fichier

'2- Vérification cases remplies

'3- Vérification doublon

'4- Verification paramétrage compte

Application.Calculation = xlCalculationAutomatic

FICHIER_NDF_OK = True

'1- Vérification bon fichier
If ActiveWorkbook.ActiveSheet.Cells(6, 2).Value <> "Version 1.08" Then
Response = MsgBox("Il ne s'agit pas d'un bon fichier ou d'une bonne
version!" & Chr(13) & Chr(13) & "Le programme va s'arrêter.", vbOKOnly +
vbExclamation, "ATTENTION", "", 1000)
FICHIER_NDF_OK = False
Exit Function
End If

'2- Vérifier le décalage des lignes ou des colonnes
If ActiveWorkbook.ActiveSheet.Cells(732, 65).Value <> "MONSIGNET" Then
Response = MsgBox("Des lignes ou des colonnes ont été effacées !" &
Chr(13) & Chr(13) & "Le programme va s'arrêter.", vbOKOnly + vbExclamation,
"ATTENTION", "", 1000)
FICHIER_NDF_OK = False
Exit Function
End If

'3-A Vérification cases remplies

For i = 11 To 16
If ActiveWorkbook.ActiveSheet.Cells(i, 3).Value = "" Then
Response = MsgBox("La cellule qui va être sélectionnée est vide
!" & Chr(13) & Chr(13) & "Le programme va s'arrêter.", vbOKOnly +
vbExclamation, "ATTENTION", "", 1000)
ActiveWorkbook.ActiveSheet.Cells(i, 3).Select
FICHIER_NDF_OK = False
Exit Function
End If
Next
If ActiveWorkbook.ActiveSheet.Cells(11, 5).Value = "" Or
ActiveWorkbook.ActiveSheet.Cells(12, 5).Value = "" Then
Response = MsgBox("La cellule qui va être sélectionnée est vide !" &
Chr(13) & Chr(13) & "Le programme va s'arrêter.", vbOKOnly + vbExclamation,
"ATTENTION", "", 1000)
Range(ActiveWorkbook.ActiveSheet.Cells(5, 5),
ActiveWorkbook.ActiveSheet.Cells(6, 5)).Select
FICHIER_NDF_OK = False
Exit Function
End If

For i = 16 To 25

If ActiveWorkbook.ActiveSheet.Cells(i, 24).Value <> 0 Then
For J = 3 To 6
If ActiveWorkbook.ActiveSheet.Cells(i, J).Value = "" Then
Response = MsgBox("La cellule qui va être sélectionnée
est vide !" & Chr(13) & Chr(13) & "Le programme va s'arrêter.", vbOKOnly +
vbExclamation, "ATTENTION", "", 1000)
ActiveWorkbook.ActiveSheet.Cells(i, J).Select
FICHIER_NDF_OK = False
Exit Function
End If
Next
End If
Next
'3-B Vérification que ce sont bien de chiffres
For i = 16 To 25

If ActiveWorkbook.ActiveSheet.Cells(i, 24).Value <> 0 Then
For J = 8 To 21
If ActiveWorkbook.ActiveSheet.Cells(i, J).Value <> "" Then
If Not IsNumeric(ActiveWorkbook.ActiveSheet.Cells(i,
J).Value) Then
Response = MsgBox("La cellule qui va être
sélectionnée est non numérique !" & Chr(13) & Chr(13) & "Le programme va
s'arrêter.", vbOKOnly + vbExclamation, "ATTENTION", "", 1000)
ActiveWorkbook.ActiveSheet.Cells(i, J).Select
FICHIER_NDF_OK = False
Exit Function
End If
End If
Next
End If
Next

End Function

Function DOUBLON_NDF_OK() As Boolean

DOUBLON_NDF_OK = True
MONACRO = ActiveWorkbook.ActiveSheet.Cells(13, 3).Value
MASEMAINE = ActiveWorkbook.ActiveSheet.Cells(12, 5).Value
MONANNEE = ActiveWorkbook.ActiveSheet.Cells(11, 5).Value



Set BaseSource = DBEngine.Workspaces(0).OpenDatabase("G:Mes
DocumentsTotoAdministratif.mdb")

MySql = "SELECT NDF.ACRO, NDF.SEMAINE, NDF.ANNEE FROM NDF WHERE
(((NDF.ACRO)=""" & MONACRO & """) AND ((NDF.SEMAINE)=" & MASEMAINE & ") AND
((NDF.ANNEE)=" & MONANNEE & "));"
'Mysql = "Select VERIF_ACRO.ACRO From VERIF_ACRO;"

Debug.Print MySql
Set Temp = BaseSource.CreateQueryDef("", MySql)
Set MASELECTION = Temp.OpenRecordset()

If MASELECTION.RecordCount <> 0 Then
DOUBLON_NDF_OK = False
End If

MASELECTION.Close
Temp.Close
Set Temp = Nothing
BaseSource.Close
Set BaseSource = Nothing

End Function

Function COMPTE_PRESENT_NDF_OK() As Boolean

COMPTE_PRESENT_NDF_OK = True
MONACRO = ActiveWorkbook.ActiveSheet.Cells(13, 3).Value

Set BaseSource = DBEngine.Workspaces(0).OpenDatabase("G:Mes
DocumentsTotoAdministratif.mdb")

MySql = "SELECT TOTOS.ACR FROM TOTOS WHERE (((TOTOS.ACR)=""" & MONACRO &
"""));"

Debug.Print MySql
Set Temp = BaseSource.CreateQueryDef("", MySql)
Set MASELECTION = Temp.OpenRecordset()

If MASELECTION.RecordCount = 0 Then
COMPTE_PRESENT_NDF_OK = False
End If

MASELECTION.Close
Temp.Close
Set Temp = Nothing
BaseSource.Close
Set BaseSource = Nothing

End Function


Function COMPTE_PARAMETRE_NDF_OK() As Boolean

COMPTE_PARAMETRE_NDF_OK = True
MONACRO = ActiveWorkbook.ActiveSheet.Cells(13, 3).Value

Set BaseSource = DBEngine.Workspaces(0).OpenDatabase("G:Mes
DocumentsTotoAdministratif.mdb")

MySql = "SELECT TOTOS.ACR, TOTOS.COMPTE FROM TOTOS WHERE
(((TOTOS.ACR)=""" & MONACRO & """) AND ((TOTOS.COMPTE)<>""""));"

Debug.Print MySql
Set Temp = BaseSource.CreateQueryDef("", MySql)
Set MASELECTION = Temp.OpenRecordset()

If MASELECTION.RecordCount = 0 Then
COMPTE_PARAMETRE_NDF_OK = False
End If

MASELECTION.Close
Temp.Close
Set Temp = Nothing
BaseSource.Close
Set BaseSource = Nothing

End Function


Sub REMONTER_NDF()

Dim BaseSource As Database
Dim QueryMag As QueryDef
Dim rstNDF, rstLNDF As Variant
Dim Nom_Magasin, Ville, commercial As String
Dim i As Long

'1- VERIFICATION FICHIER
If FICHIER_NDF_OK = False Then Exit Sub

'2-VERIFICATION NOTE DEJA MONTEE
Rep = vbYes
If DOUBLON_NDF_OK = False Then
Rep = MsgBox("Une note de frais similaire a déjà été montée.
Voulez-vous continuer ?", vbYesNo)
End If
If Rep = vbNo Then
Exit Sub
End If

'3-VERIFICATION COMPTE PRESENT
If COMPTE_PRESENT_NDF_OK = False Then
MsgBox "Le compte n'est pas présent dans la base. La note de frais ne
sera pas montée !"
Exit Sub
End If

'4-VERIFICATION COMPTE PARAMETRE
If COMPTE_PARAMETRE_NDF_OK = False Then
MsgBox "Le compte n'est pas paramétré. La note de frais ne sera pas
montée !"
Exit Sub
End If


'5-DEBUT DE LA REMONTEE

Set BaseSource = DBEngine.Workspaces(0).OpenDatabase("G:Mes
DocumentsTotoAdministratif.mdb")
Set rstNDF = BaseSource.OpenRecordset("NDF", adOpenDynamic,
adLockOptimistic)


If rstNDF.RecordCount = 0 Then

NOUVELID = 1

Else

rstNDF.MoveFirst
MAXID = 0
i = 1
While Not rstNDF.EOF
If rstNDF("ID") > MAXID Then MAXID = rstNDF("ID")
rstNDF.MoveNext
Wend
NOUVELID = MAXID + 1

End If

MONNOM = Cells(11, 3).Value
MONPRENOM = Cells(12, 3).Value
MONACRO = Cells(13, 3).Value
MONEQUIPE = Cells(14, 4).Value
MONANNEE = Cells(11, 5).Value
MASEMAINE = Cells(12, 5).Value
MONPAIEMENT = Cells(15, 3).Value
MADATEREMISE = Cells(16, 3).Value
MONMONTANT = Cells(22, 24).Value

rstNDF.AddNew
rstNDF("ID") = NOUVELID
rstNDF("NOM") = MONNOM
rstNDF("PRENOM") = MONPRENOM
rstNDF("ACRO") = MONACRO
rstNDF("EQUIPE") = MONEQUIPE
rstNDF("ANNEE") = MONANNEE
rstNDF("SEMAINE") = MASEMAINE
rstNDF("PAIEMENT") = MONPAIEMENT
rstNDF("DATE_REMISE") = MADATEREMISE
rstNDF("DATE_REMONTEE") = Date
rstNDF("STATUT") = 1
rstNDF.Update


Avatar
michdenis
Bonjour stanislasRB,

voici un exemple à partir de DAO : Ajouter des enregistrements à une table Access déjà existante, les données d'un tableau sur une
feuille excel .

Dans l'exemple suivant, il ne te restera plus qu'à adapter le nom des
objets selon ton application.

toto = Nom de la table dans la base de données Comptoir.mdb

Pour ce qui est du champ de numéro automatique dans ta base de données, il va se mettre à jour tout seul !

Évidemment, tu dois ajouter la bibliothèque : Microsoft DAO 3.6 objects Librairy
'--------------------------------------------
Sub ExporterVersAccess()

Dim bd As DAO.Database
Dim Rst As DAO.Recordset

With Worksheets("Feuil1")
.Range("B4:B" & .Range("B65536").End(xlUp).Row).Name = "Plage"
End With

Set bd = OpenDatabase(ThisWorkbook.FullName, False, False, "excel 8.0")

bd.Execute "INSERT INTO toto IN 'C:ExcelComptoir.mdb' SELECT * FROM [Plage]"
ThisWorkbook.Names("Plage").delete
bd.Close
Set bd = Nothing
End Sub
'--------------------------------------------


Salutations!


"stanislasRB" a écrit dans le message de news:

Bonjour,
Je souhaite exporter des données d'un classeur xl vers une base access par
vba, sans avoir à ouvrir cette base. Je dispose d'office2003, je suis d'un
niveau correct en vba, mais je ne maitrise absolument pas les echanges entre
applications, et je ne trouve pas de solution dans l'aide.
merci par avance,