Library code snippets
Create Table in a Database
By amoibade, published on 09 Mar 2003
This code shows you how to create a table and it's indexes in a database at run time.
Private Sub Command1_Click()
Dim MyDatabase As Database
Dim NewTable As TableDef
Dim MyArtist As dao.Index
Dim MyIndex2 As dao.Index
Dim MyIndex3 As dao.Index
' open database
Set MyDatabase = OpenDatabase(App.Path + "\mp3Base.mdb")
'create the table
Set NewTable = MyDatabase.CreateTableDef("mp3New")
On Error Resume Next
'delete the table if it already exists
MyDatabase.TableDefs.Delete NewTable.Name
'add the fields in the table, those used below are just an example
With NewTable
.Fields.Append .CreateField("Title", dbText, 30)
.Fields.Append .CreateField("Artist", dbText, 30)
.Fields.Append .CreateField("Album", dbText, 30)
.Fields.Append .CreateField("Year", dbText, 4)
.Fields.Append .CreateField("Comment", dbText, 30)
.Fields.Append .CreateField("Genre", dbText, 1)
.Fields.Append .CreateField("Position", dbText, 10)
End With
'add indexes in the table
Set MyArtist = NewTable.CreateIndex("Artist")
MyArtist.Fields.Append MyArtist.CreateField("Artist")
NewTable.Indexes.Append MyArtist
Set MyIndex2 = NewTable.CreateIndex("Title")
MyIndex2.Fields.Append MyIndex2.CreateField("Title")
NewTable.Indexes.Append MyIndex2
Set MyIndex3 = NewTable.CreateIndex("Position")
MyIndex3.Fields.Append MyIndex3.CreateField("Position")
NewTable.Indexes.Append MyIndex3
NewTable.Indexes.Refresh
MyDatabase.TableDefs.Append NewTable
'close database
MyDatabase.Close
End Sub
Related articles
Related discussion
-
ditto
by zapthedingbat (2 replies)
-
Mousewheel
by jonh (3 replies)
-
True multithread VB source code controls
by James Crowley (3 replies)
-
Rely
by Yujvendra Verma (4 replies)
-
True multithread VB source code controls
by James Crowley (3 replies)
hello sir actually I need help regarding connectivity of VB to oracle how it can be setup? please post it ! thank You!
Hi.
If is possible can you explain me how to do create database in the vb 6. either from access of from vb 6 it self
Thank you.
George
55
Dear Sir,
I want to know How to Open Pass Word MsAccess DataBase at Rintime in DAO (Data Acsses Object)
Please send me kind reply to my E-Mail
My E-mail Address : nishantha_213@yahoo.com
Just write :
Dim db As Database
Dim tdf As DAO.TableDef
Set db = CurrentDb
Set tdf = db.TableDefs("table")
tdf.Fields.Append tdf.CreateField("field1", dbDate)
Can we add a column to a table that already exists (with dao)?
DAO is under "project" in the menu of vb6
click references
then it is under microsoft Dao 3.6
I know where it is ....just don't really know how to use it. LOL
I am trying to add pics to my table database
how can I do this? anyone?
www.b2bproject.net
Well, actually you need to add the dao reference, not the dao component. That's why you can't find it.
i dun know where to find the microsoft dao componet? can anyone help....