• Increase font size
  • Default font size
  • Decrease font size

Create Table in Microsoft Access From Visual Basic 6.0

E-mail Print PDF

This article shows how to create Table in Microsoft Access from Visual Basic 6.0 programming language. If you still use Visual Basic Programming Language for small project connecting with Database in Microsoft Access then you might need the below code to proceed the creation of Table in Microsoft Access from your own software per se by do not need to open Microsoft Access application as usual.

  1. Assume that we have one MS Access file (a.mdb) in drive C:\ with no Table
  2. Create Visual Basic 6.0 project and connect to the above MS Access file using DAO
  3. (In this example we create one Table named tblTest with four columns)
* Note: Using DAO by set Visual Basic reference (Microsoft DAO 3.6 Object Library)
Dim db as DAO.Database
Dim tbd As DAO.TableDef
set db=OpenDatabase("C:\a.mdb")
Set tbd = db.CreateTableDef("tblTest")
With tbd
  .Fields.Append .CreateField("ID", dbText)
  .Fields.Append .CreateField("Name", dbText)
  .Fields.Append .CreateField("Sex", dbText)
  .Fields.Append .CreateField("DOB", dbDate)
End With
db.TableDefs.Append tbd