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 50 51 52 53 54 55
| Sub creatproduit(db As Database, name As String)
Dim tb As TableDef
Set tb = New TableDef
tb.name = name
createfield tb, "ref", dbText, 15, False, True
createfield tb, "desig", dbText, 30
createfield tb, "q", dbSingle
'CreateIndex tb, "xref", Array("ref"), True, True
db.TableDefs.Append tb
End Sub
Sub createfield(tb As TableDef, name As String, t As Integer, Optional size As Integer = 0, Optional azl As Boolean = True, Optional notnull As Boolean = False)
Dim f As Field
Set f = New Field
f.name = name
f.Type = t
If (size > 0) Then f.size = size
tb.Fields.Append f
tb.Fields(name).AllowZeroLength = azl
tb.Fields(name).Required = notnull
End Sub
Sub creatindex(tb As TableDef, name As String, champs As Variant, Optional primary As Boolean = False, Optional unique As Boolean = False)
Dim ndx As Index
Set ndx = New Index
ndx.name = name
For i = LBound(champs) To UBound(champs)
ndx.Fields.Append ndx.createfield(champs(i))
Next
ndx.primary = primary
ndx.unique = unique
tb.Indexes.Append ndx
End Sub
Sub createtable(db As Database)
creatproduit db, "produit"
End Sub
Private Sub Form_Load()
Dim db As Database
If (Dir("c:\dotnet.mdb") <> "") Then
Kill ("c:\dotnet.mdb")
End If
Set db = CreateDatabase("c:\dotnet.mdb", dbLangGeneral + ";pwd=dot")
createtable db
End Sub |
Partager