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
-
VB6 Runtime error 381 subsript out of range Error
by Uncle (2 replies)
-
passing and reading parameters from using Shell
by jigartoliya (0 replies)
-
Convert C++ code to VB6
by mawcot (4 replies)
-
listbox scrollbar
by Dennijr (10 replies)
-
Can you describe Above simple VB6 code?
by pramodmca09 (0 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
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
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....
This thread is for discussions of Create Table in a Database.