VBA code that creates a table in Microsoft Access


 Sub CreateTable()

    Dim db As DAO.Database

    Dim tbl As DAO.TableDef

    Set db = CurrentDb()

    Set tbl = db.CreateTableDef("MyTable")

    tbl.Fields.Append tbl.CreateField("ID", dbLong)

    tbl.Fields.Append tbl.CreateField("Name", dbText, 255)

    tbl.Fields.Append tbl.CreateField("Age", dbInteger)

    db.TableDefs.Append tbl

End Sub


This code creates a new table called "MyTable" with three fields: "ID", "Name", and "Age". The "ID" field is of type "Long", while the "Name" field is of type "Text" with a maximum length of 255 characters, and the "Age" field is of type "Integer". The table is then appended to the database.


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.