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 43 44
| Private Sub Commande0_Click()
Dim rst As DAO.Recordset
Dim Odb As DAO.Database
Dim intfic As Integer
Dim i As Integer
Dim Nbr1 As Long
Set Odb = CurrentDb
Set rst = Odb.OpenRecordset("SELECT Champs1, Champs2, Champs3 FROM Table1")
Nbr1 = 0
'Ouverture du fichier texte ou seront insérés les données
intfic = FreeFile
Open "C:\Documents and Settings\...Test.txt" For Append As intfic
'Ecriture de l'en-tête
Print #intfic, "Champs1", "$", "Champs2", "$", "Champs3"
'Parcours du recordset
Do While Not rst.EOF
For i = 1 To Len(rst("Champs3"))
If Mid(rst("Champs3"), i, 1) = "1" Then
Nbr1 = Nbr1 + 1
ElseIf Mid(rst("Champs3"), i, 1) = "2" Then
Nbr1 = Nbr1 + 1
End If
Next
'Inscription des lignes
Print #intfic, rst.Fields("Champs1"), "$", rst.Fields("Champs2"), "$", Nbr1
Nbr1 = 0
rst.MoveNext
Loop
'Fermeture du fichier
Close intfic
Nbr1 = 0
Set rst = Nothing
DoCmd.Close
End Sub |
Partager