how do i add new tables to a mdb database and then alter the fields?
Printable View
how do i add new tables to a mdb database and then alter the fields?
By using the TableDef and Field objects, all documented. If you need sample code, just ask.
i do, that's why i did!
This uses DAO (bit different to your last question), hopefully someone else will post a ADO way of doing this but...
(the text bit at the end I think is optional, but specifies the type of column - what format the entries are in ie number, text etc...)Code:Dim db as database, rs as recordset
Set DB = DAO.OpenDatabase("C:\A_database_Here.mdb)DB.Execute "CREATE TABLE TableName_Here" & "(Column_Name_Here TEXT)"
Set rs = db.openrecordset("TableName_Here")
Hope this helps :)
Here's another way of doing it with only DAO objects.
Hope this helps. I haven't really had to use it in ADO yet but I'll check it out.
Dim dbCheck As Database
Dim tdfCheck As TableDef
Dim fldCheck As Field
'If the database exists, open it.
Set dbCheck = DBEngine.OpenDatabase("c:\MyDB.mdb")
'Else Create the database.
Set dbCheck = DBEngine.CreateDatabase("c:\MyDB.mdb", dbLangGeneral)
'Create the table definition
Set tdfCheck = dbCheck.CreateTableDef("MyTable")
'Create the field
Set fldCheck = tdfCheck.CreateField("MyField", dbText, 20)
'Set up field parameters.
fldCheck.AllowZeroLength = False
fldCheck.Required = True
'Append the field definition to the table definition.
tdfCheck.Fields.Append fldCheck
'Append the table definiition to the database
dbCheck.TableDefs.Append tdfCheck
'Close the database explicitly, otherwise the changes won't be saved.
dbCheck.Close
thanks