|
-
Jan 1st, 2000, 01:43 PM
#3
Thread Starter
New Member
Very appreciated your code.
I used it to code as:
'***************************************
Sub MakeNewTable(tbName As String, from_nm As String)
'tbName is the table to be created
'from_nm is the source table
On Error GoTo error_newTB
Dim Mydb As Database
Set Mydb = OpenDatabase("c:\mdb\my.mdb")
Dim tb As TableDef
Dim ind As Index
Mydb.TableDefs.Refresh
Set tb = Mydb.CreateTableDef(name:=tbName)
'create field and attribute
tb.Fields.Append tb.CreateField(name:="id", Type:=dbLong)
tb.Fields("id").Attributes = tb.Fields("id").Attributes + dbAutoIncrField
'make it autonumber
tb.Fields.Append tb.CreateField(name:="name", Type:=dbText, Size:=50)
tb.Fields.Append tb.CreateField(name:="total", Type:=dbLong)
tb.Fields.Append tb.CreateField(name:="create_date", Type:=dbDate)
tb.Fields.Append tb.CreateField(name:="end_date", Type:=dbDate)
tb.Fields.Append tb.CreateField(name:="desc", Type:=dbMemo)
tb.Fields.Append tb.CreateField(name:="recent_date", Type:=dbDate)
tb.Fields.Append tb.CreateField(name:="flag", Type:=dbText, Size:=1)
Mydb.TableDefs.Append tb
'create index
Dim i As Integer
Set ind = New Index
For i = 0 To Mydb.TableDefs(from_nm).Indexes.Count - 1
ind.name = Mydb.TableDefs(from_nm).Indexes(i).name
ind.Fields = Mydb.TableDefs(from_nm).Indexes(i).Fields
ind.Unique = Mydb.TableDefs(from_nm).Indexes(i).Unique
ind.Primary = Mydb.TableDefs(from_nm).Indexes(i).Primary
tb.Indexes.Append ind
Next
Mydb.Close
Send ("OK")
Exit Sub
error_newTB:
Send ("ERROR")
End Sub
'*****************************************
But I got two questions:
(1)How to make id as [main] primary index?
(2)How to make default value for a certain field I created?
Thanks all!
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
|