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 45 46 47 48 49
|
Sub CreerTable()
Dim dft As TableDef, chp1 As Field, chp2 As Field, chp3 As Field, chp4 As Field, chp5 As Field, chp6 As Field, _
chp7 As Field, chp8 As Field, chp9 As Field, chp10 As Field, chp11 As Field, chp12 As Field, idx As Index, _
chpIndex As Field, bds as Database
Dim tdfLoop As TableDef
Set Bds= CurrentDb()
bds.TableDefs.Delete "Depenses" 'suppression de la table Depenses
' Crée une nouvelle table avec douze champs.
Set dft = bds.CreateTableDef("Depenses")
Set chp1 = dft.CreateField("RefDepense", dbLong)
chp1.Attributes = chp1.Attributes + dbAutoIncrField
Set chp2 = dft.CreateField("ObjetDepense", dbText, 255)
Set chp3 = dft.CreateField("RefFournisseur", dbLong)
Set chp4 = dft.CreateField("LigneComptable", dbText, 10)
Set chp5 = dft.CreateField("MontantEngage", dbSingle)
Set chp6 = dft.CreateField("DateEngagement", dbDate)
Set chp7 = dft.CreateField("Commentaire", dbMemo)
chp7.AllowZeroLength = True
Set chp8 = dft.CreateField("DateFacture", dbDate)
Set chp9 = dft.CreateField("MontantFactureHT", dbSingle)
chp9.DefaultValue = Null
Set chp10 = dft.CreateField("TauxTVA", dbSingle)
Set chp11 = dft.CreateField("NumeroFacture", dbText, 20)
Set chp12 = dft.CreateField("Verif", dbBoolean)
chp11.DefaultValue = 0
' Ajoute les champs.
dft.Fields.Append chp1
dft.Fields.Append chp2
dft.Fields.Append chp3
dft.Fields.Append chp4
dft.Fields.Append chp5
dft.Fields.Append chp6
dft.Fields.Append chp7
dft.Fields.Append chp8
dft.Fields.Append chp9
dft.Fields.Append chp10
dft.Fields.Append chp11
dft.Fields.Append chp12
' Crée une première clé d'index.
Set idx = dft.CreateIndex("Clé primaire")
Set chpIndex = idx.CreateField("RefDepense", dbLong)
' Ajoute les champs d'index.
idx.Fields.Append chpIndex
' Attribue la propriété Primary.
idx.Primary = True
' Ajoute l'index.
dft.Indexes.Append idx
End Sub |
Partager