Enregistrement

AABS Messages postés 50 Date d'inscription vendredi 14 mars 2003 Statut Membre Dernière intervention 29 janvier 2007 - 11 avril 2004 à 21:11
GIRIB Messages postés 4 Date d'inscription samedi 14 février 2004 Statut Membre Dernière intervention 13 avril 2004 - 13 avril 2004 à 10:44
BonJour aux amoureux du VB
ma question est la suivante:
comment enregistrer une table (sous Access) dans un fichier texte avec Visual Basic 6.0
Thx

1 réponse

GIRIB Messages postés 4 Date d'inscription samedi 14 février 2004 Statut Membre Dernière intervention 13 avril 2004
13 avril 2004 à 10:44
Une proposition de solution qui devrit marcher avec toutes les tables.

Dim Db As Database
Private Sub Command1_Click()
Set Db = OpenDatabase("mabase.mdb")
SauverText "MaTable", "FicTextBase.txt"
End Sub

Private Sub SauverText(TableBase As String, NomFic As String)
Dim Rs As Recordset
Dim J As Integer
Dim Car As String ' Séparateur de champ
Dim Ch As String
Car = vbTab ' Séparation par tabulation
Set Rs = Db.OpenRecordset(" Select * from " & TableBase)
Open NomFic For Output As #1
Ch = "" ' On commence par les noms des champs en première ligne
For J = 0 To Rs.Fields.Count - 1
Ch = Ch & Rs.Fields(J).Name & Car
Next J
Print #1, Ch
While Not Rs.EOF
Ch = ""
For J = 0 To Rs.Fields.Count - 1
If IsNull(Rs.Fields(J).Value) Then
Ch = Ch & Car
Else
Ch = Ch & CStr(Rs.Fields(J).Value) & Car
End If
Next J
Print #1, Ch
Rs.MoveNext
Wend
Close #1
End Sub
0
Rejoignez-nous