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
| Option Compare Database
Option Explicit
Function demo_CSV()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strLine As String
Dim iFileNbr As Integer
Dim strSQL As String
Set db = Application.CurrentDb
Set rst = db.OpenRecordset("Table1")
'The file is created as a text file because the Transfertext method relies on Windows locales and requires
'a transfer template to be saved locally
'prendre le premier numero de fichier libre
iFileNbr = FreeFile
'ouvrir le fichier
Open "C:\Temp\Test.csv" For Output As iFileNbr
'parcourir la table avec mes données
rst.MoveFirst
Do Until rst.EOF
strLine = rst![Entier]
'composer la ligne en séparant les champs par le caractère de mon choix
strLine = strLine & ";" & rst![NombreDouble]
strLine = strLine & ";" & rst![NombreDecimal]
'De la Table1, j'exporte trois champs. Le premier champ s'appelle 'Entier', le second 'NombreDouble' et le troisieme s'appelle 'NombreDecimal'
'écrire la ligne sur le fichier texte
Print #iFileNbr, strLine
rst.MoveNext
Loop
'fermer le fichier
Close iFileNbr
'supprimer les pointeurs
Set rst = Nothing
Set db = Nothing
End Function |
Partager