Dbase 5.0

anamorph - 14 juin 2000 à 19:48
 jazzyj - 15 juin 2000 à 13:09
Comment ouvrir et chercher des données dans un fichier dbase 5 sous visual basic 6

merci par avance a celui qui me donnera une réponce.

Anamorph

1 réponse

Salut,voici un exemple d une sub qui vérifie si un .dbf existe sinon le crée en utilisant les infos de noms,type et longeur de champ qui se trouve dans un autre .dbf.Comme tu pourras le constater ta database c est le répertoire ou se trouve ton fichier(completepath & socsel).ton fichier devient une table crée grace a createtabledef et tu lis grace a la methode openrecordset.

Jazzyj. a votre service .

Public Sub CreateDbfFileEmpty(TypeJvOrJo As String)
Dim FS As New FileSystemObject
Dim dbj As DAO.Database
Dim td As TableDef, rsrs As DAO.Recordset, td2 As DAO.TableDef, f As DAO.Field
Set FS = CreateObject("Scripting.FileSystemObject")
Set dbj = OpenDatabase(CompletePath & SocSel & "", False, 0, "Dbase IV;")

Select Case TypeJvOrJo
Case "Jv":
If FS.FileExists(CompletePath & "jv00ven" & ".dbf") Then
Exit Sub
'End If
ElseIf Not FS.FileExists(CompletePath & "jva" & SocSel & ".dbf") Then
'MsgBox "Could not find " & varFichSourc & "." & vbCr & "This file will not be processed.", vbInformation
Exit Sub
Else
Set td = dbj.CreateTableDef(CompletePath & SocSel & "" & "jva" & SocSel & ".dbf", , CompletePath & SocSel & "" & "jva" & SocSel & ".dbf", "Dbase IV")
Set td2 = New TableDef
Set rsrs = dbsTemp21.OpenRecordset("select * from " & _
td.Name, dbOpenDynaset, dbReadOnly)
While Not rsrs.EOF
Set f = New DAO.Field
f.Name = rsrs("field_name")
If rsrs("field_type") = "C" Then
f.Type = dbText
ElseIf rsrs("field_type") = "N" Then
f.Type = dbDouble
End If
f.Size = rsrs("field_len")
td2.Fields.Append f
rsrs.MoveNext
Wend
td2.Name = "jv00ven"
dbj.TableDefs.Append td2
End If
Case "Jo": '
If FS.FileExists(CompletePath & "" & SocSel & "" & "jo00OOO" & ".dbf") Then
Exit Sub ' a changer jv00ven
ElseIf FS.FileExists(CompletePath & "" & "jo00OOO" & ".dbf") Then
FS.CopyFile CompletePath & "" & "jo00OOO" & ".dbf", CompletePath & "" & SocSel & "" & "jo00OOO" & ".dbf"
Exit Sub

'End If
'End If
ElseIf Not FS.FileExists(CompletePath & SocSel & "" & "Jfo" & SocSel & ".dbf") Then
'MsgBox "Could not find " & varFichSourc & "." & vbCr & "This file will not be processed.", vbInformation
Exit Sub 'error
Else
Set td = dbj.CreateTableDef(CompletePath & SocSel & "" & "jfo" & SocSel & ".dbf", , CompletePath & SocSel & "" & "jva" & SocSel & ".dbf", "Dbase IV")
Set td2 = New TableDef
Set rsrs = dbsTemp21.OpenRecordset("select * from " & _
td.Name, dbOpenDynaset, dbReadOnly)
While Not rsrs.EOF
Set f = New DAO.Field
f.Name = rsrs("field_name")
If rsrs("field_type") = "C" Then
f.Type = dbText
ElseIf rsrs("field_type") = "N" Then
f.Type = dbDouble
End If
f.Size = rsrs("field_len")
td2.Fields.Append f
rsrs.MoveNext
Wend
td2.Name = "jo00OOO"
dbj.TableDefs.Append td2
End If
End Select
End Sub
0
Rejoignez-nous