Recherche
Recherche
Les mémos
 ↑  
Je débute...
Visites

 992295 visiteurs

 1 visiteur en ligne

La méthode par le SQL est nettement plus simple, mais au détriment d'un manque de possibilités quant aux propriétés accessibles.

Créer une Table en code SQL

CREATE TABLE LaTable (
	LeTexte CHAR(50),
	LaDate DATE not null,
 	LaMonnaie Currency,
    	LeNombreReel Double,
    	LeNombreEntierLong Long,
    	LeChampMemo Memo,
   	OuiNon YESNO,
    	NoAuto counter,
    	CONSTRAINT PrimaryKey PRIMARY KEY (NoAuto));

Créer une table en VBA - N'oubliez pas la référence DAO

Sub CreateTable()
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Set dbs = CurrentDb()
Set tdf = dbs.CreateTableDef("NouvelleTable")
Set fld = tdf.CreateField("NoAuto", dbLong)
        fld.OrdinalPosition = 1
        fld.Attributes = dbAutoIncrField
        tdf.Fields.Append fld
Set fld = tdf.CreateField("ChampTexte", dbText)
        fld.OrdinalPosition = 2
        fld.Size = 100
        fld.Required = True
        fld.AllowZeroLength = False
        tdf.Fields.Append fld
Set fld = tdf.CreateField("EntierLong", dbLong)
        fld.OrdinalPosition = 3
        fld.Attributes = dbFixedField
        tdf.Fields.Append fld
Set fld = tdf.CreateField("Booleen", dbBoolean)
        fld.OrdinalPosition = 4
        tdf.Fields.Append fld
Set fld = tdf.CreateField("Byte", dbByte)
        fld.OrdinalPosition = 5
        tdf.Fields.Append fld
Set fld = tdf.CreateField("Entier", dbInteger)
        fld.OrdinalPosition = 6
        tdf.Fields.Append fld
Set fld = tdf.CreateField("Monétaire", dbCurrency)
        fld.OrdinalPosition = 7
        tdf.Fields.Append fld
Set fld = tdf.CreateField("ReelSimple", dbSingle)
        fld.OrdinalPosition = 8
        tdf.Fields.Append fld
Set fld = tdf.CreateField("ReelDouble", dbDouble)
        fld.OrdinalPosition = 9
        tdf.Fields.Append fld
Set fld = tdf.CreateField("ChampDate", dbDate)
        fld.OrdinalPosition = 10
        tdf.Fields.Append fld
Set fld = tdf.CreateField("Binary", dbBinary)
        fld.OrdinalPosition = 11
        tdf.Fields.Append fld
Set fld = tdf.CreateField("ChampMemo", dbMemo)
        fld.OrdinalPosition = 12
        tdf.Fields.Append fld
Set fld = tdf.CreateField("ChampOLE", dbBigInt)
        fld.OrdinalPosition = 13
        tdf.Fields.Append fld
      dbs.TableDefs.Append tdf
      RefreshDatabaseWindow
      MsgBox "La table " & tdf.Name & " a été créée"
      Set fld = Nothing
      Set tdf = Nothing
      Set dbs = Nothing
End Sub

Catégorie : Les mémos - Tables
Page lue 13308 fois