|
-
Sep 6th, 2000, 04:31 AM
#1
Thread Starter
Conquistador
another db question? adding sheets
how do i add new tables to a mdb database and then alter the fields?
-
Sep 6th, 2000, 05:24 AM
#2
Member
By using the TableDef and Field objects, all documented. If you need sample code, just ask.
Barend
JHB-SA
Nothing is impossible, except skiing through a revolving door.
-
Sep 6th, 2000, 05:30 AM
#3
Thread Starter
Conquistador
-
Sep 6th, 2000, 06:27 AM
#4
This uses DAO (bit different to your last question), hopefully someone else will post a ADO way of doing this but...
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")
(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...)
Hope this helps
-
Sep 6th, 2000, 07:08 AM
#5
Member
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
Barend
JHB-SA
Nothing is impossible, except skiing through a revolving door.
-
Sep 7th, 2000, 12:28 AM
#6
Thread Starter
Conquistador
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|