Exemple de creation d'une base de donnees

Description

Il faut juste changer les parametres en fonction de l'application et ca va marcher, et il y a toutes les procedures necessaires pour creer une base de donnees

Source / Exemple :


Dim db As Database
Sub test(NBD As String)
    If (Dir(NBD) = "") Then
        Set db = CreateDatabase(NBD, dbLangGeneral)
        If Not db Is Nothing Then
            creer_tables db
            Else
            MsgBox "erreur"
        End If
    End If
End Sub
Sub champs(tb As TableDef, nom As String, t As Integer, Optional s As Integer, Optional z As Boolean = True, Optional r As Boolean = False)
Dim f As Field
Set f = New Field
    f.Name = nom
    f.Type = t
    If (s <> 0) Then f.Size = s
    tb.Fields.Append f
    f.AllowZeroLength = z
    tb.Fields(nom).Required = r
End Sub
Sub indexer(tb As TableDef, nom As String, ref As String, Optional t As Boolean)
Dim ind As Index
Set ind = New Index
    ind.Name = nom
    ind.Fields = ref
    ind.Primary = True
    ind.Unique = t
    tb.Indexes.Append ind
End Sub

Sub creer_produit(db As Database, nom As String)
Dim tb As New TableDef
    tb.Name = nom
    champs tb, "ref", dbText, 10, True, False
    champs tb, "desig", dbText, 10
    champs tb, "qs", dbInteger
    champs tb, "pu", dbInteger
    indexer tb, "xcode", "ref"
    db.TableDefs.Append tb
End Sub
Sub creer_client(db As Database, nom As String)
Dim tb As New TableDef
    tb.Name = nom
    champs tb, "CIN", dbText, 10
    champs tb, "nom", dbText, 20
    champs tb, "prenom", dbText, 20
    champs tb, "adresse", dbText, 30
    champs tb, "tele", dbInteger, 11
    champs tb, "fax", dbInteger, 20
    indexer tb, "xcode", "CIN"
    db.TableDefs.Append tb
End Sub
Sub creer_facture(db As Database, nom As String)
Dim tb As New TableDef
    tb.Name = nom
    champs tb, "Nfact", dbText, 10
    champs tb, "CIN", dbText, 10
    champs tb, "date", dbDate
    indexer tb, "xcode", "Nfact"
    db.TableDefs.Append tb
End Sub
Sub creer_articles(db As Database, nom As String)
Dim tb As New TableDef
    tb.Name = nom
    champs tb, "Nfact", dbText, 10
    champs tb, "ref", dbText, 10
    champs tb, "q", dbInteger
    indexer tb, "xcode", "Nfact"
    db.TableDefs.Append tb
End Sub
Sub creer_tables(db As Database)
    creer_produit db, "produit"
    creer_client db, "client"
    creer_facture db, "facture"
    creer_articles db, "articles"
End Sub

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.