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
|
Private Sub cmdWriteIntoFile_Click()
Dim oFSO As Scripting.FileSystemObject
Dim oTextStream As Scripting.TextStream
Dim oDB As DAO.Database
Dim oRS As DAO.Recordset
Dim SQLCommand As String
Dim strLine As String
Dim strFieldValue As String
Dim strFileName As String
Dim I As Long
Dim F As Long
Set oFSO = New Scripting.FileSystemObject
strFileName = "C:\_Test\Un fichier.txt"
With oFSO
Set oTextStream = .CreateTextFile(strFileName, True, False)
End With
SQLCommand = "SELECT * FROM [Détails commandes complets] _
WHERE [N° commande] = " & Me![N° commande]
Set oDB = CurrentDb
Set oRS = oDB.OpenRecordset(SQLCommand, dbOpenDynaset)
With oRS
Do While Not .EOF
I = I + 1
For F = 0 To .Fields.Count - 1
strFieldValue = strFieldValue & .Fields(F).Value & ";"
Next
strLine = strFieldValue
oTextStream.WriteLine strLine
strFieldValue = vbNullString
.MoveNext
Loop
.Close
End With
oDB.Close
Set oRS = Nothing
Set oDB = Nothing
End Sub |
Partager