eric_epinay
Messages postés3Date d'inscriptionsamedi 18 août 2007StatutMembreDernière intervention27 novembre 2008
-
27 nov. 2008 à 17:10
cs_eren
Messages postés38Date d'inscriptionvendredi 3 janvier 2003StatutMembreDernière intervention27 novembre 2008
-
27 nov. 2008 à 17:41
Bonjour?
je cherche une solution , pour créer depuis excel, une macro, qui me permette d'ajouter des valeurs placées dans des cellules excel, vers une table access
est ce possible? quelqu'un peut il m'aider
Y a t'il une procédure pour
Depuis excel,
Ouvrir un fichier access, ouvrir une table et y placer des données ?
cs_eren
Messages postés38Date d'inscriptionvendredi 3 janvier 2003StatutMembreDernière intervention27 novembre 2008 27 nov. 2008 à 17:41
Bonjour,
'Export data from Excel to Access (ADO)
'If you want to export data to an Access table from an Excel worksheet,
'the macro example below shows how this can be done:
Sub ADOFromExcelToAccess()
' Ajouter le complément Microsoft ActiveX Data Objects 2.x Library
' exports data from the active worksheet to a table in an Access database
' this procedure must be edited before use
Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As Long
' connect to the Access database
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\FolderName\DataBaseName.mdb;"
' open a recordset
Set rs = New ADODB.Recordset
rs.Open "TableName", cn, adOpenKeyset, adLockOptimistic, adCmdTable ' all records in a table
r = 2 ' the start row in the worksheet
Do While Len(Range("A" & r).Formula) > 0 ' repeat until first empty cell in column A
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("FieldName1") = Range("A" & r).Value
.Fields("FieldName2") = Range("B" & r).Value
.Fields("FieldName3") = Range("C" & r).Value
' add more fields if necessary...
.Update ' stores the new record
End With
r = r + 1 ' next row
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub