Bonjour,
C'est une base de données au format access?
Tu utilise VB6?
si oui : Voici un exemple de création de tables, de champs, et de relations en VB6
Public Sub CréationTables()
Dim T As DAO.TableDef
Dim f As DAO.Field
Dim r As DAO.Relation
Dim ix As DAO.Index
Dim prp As DAO.Property
Dim x As Long
On Error GoTo TraiteErreur
' ---- Création Table Composants ----
Set T = Db.CreateTableDef("Composants")
'Id : NuméroAuto + PrimaryKey
Set f = T.CreateField("Id", DAO.DataTypeEnum.dbLong)
f.Attributes = DAO.dbAutoIncrField
T.Fields.Append f
Set ix = T.CreateIndex("PrimaryKey")
With ix
.Fields.Append .CreateField("Id")
.Primary = True
End With
T.Indexes.Append ix
'Libellé : Texte(50) + Chaîne vide autorisée
Set f = T.CreateField("Libellé", DAO.DataTypeEnum.dbText, 50)
f.AllowZeroLength = True
f.Required = False
T.Fields.Append f
Db.TableDefs.Append T
' ---- Création Table Constituants ----
Set T = Db.CreateTableDef("Constituants")
'Id : NuméroAuto + PrimaryKey
Set f = T.CreateField("Id", DAO.DataTypeEnum.dbLong)
f.Attributes = DAO.dbAutoIncrField
T.Fields.Append f
Set ix = T.CreateIndex("PrimaryKey")
With ix
.Fields.Append .CreateField("Id")
.Primary = True
End With
T.Indexes.Append ix
'Flux : Numérique + Décimal Auto
Set f = T.CreateField("Flux", DAO.DataTypeEnum.dbLong)
f.DefaultValue = 0
T.Fields.Append f
'Composant : Numérique + Décimal Auto
Set f = T.CreateField("Composant", DAO.DataTypeEnum.dbLong)
f.DefaultValue = 0
T.Fields.Append f
'Pourcentage : Réel double + 2 Décimals
Set f = T.CreateField("Pourcentage", DAO.DataTypeEnum.dbDouble)
f.DefaultValue = 0
T.Fields.Append f
Db.TableDefs.Append T
Db.TableDefs.Refresh
Set T = Db.TableDefs("Constituants")
Set f = T.Fields("Pourcentage")
Set prp = f.CreateProperty("DecimalPlaces", dbByte, CByte(2))
f.Properties.Append prp
T.Fields.Refresh
' ----- Relation -> Composants vers constituants -----
Set r = Db.CreateRelation()
With r
.Name = "ComposantsConstituants"
.Table = "Composants"
.ForeignTable = "Constituants"
.Attributes = DAO.dbRelationLeft
Set f = .CreateField("Id")
f.ForeignName = "Composant"
r.Fields.Append f
End With
Db.Relations.Append r
TraiteErreur:
If Err = 0 Then
Set T = Nothing
Set f = Nothing
Set ix = Nothing
Set r = Nothing
MsgBox "Les Tables Constituants et Composants ont été créées avec succés.", vbInformation, "Confirmation de création"
Else
Set T = Nothing
Set f = Nothing
Set ix = Nothing
End If
End Sub
Ricks27