1. I used the code below to add several fields to a table and to add another field to the primary Key.
'''edit table employee
Set tbl = dbs.TableDefs("employee"
With tbl
.Fields.Append .CreateField("photograph", dbText, 20)
.Fields.Append .CreateField("IsEmployee", dbText, 1)
.Fields.Append .CreateField("salary_group", dbInteger, 2)
.Fields.Append .CreateField("jobcode", dbText, 10)
.Fields.Append .CreateField("jobname", dbText, 20)
.Fields.Append .CreateField("Division", dbText, 30)
.Fields.Append .CreateField("Branch", dbText, 30)
End With
dbs.TableDefs.Append tbl
With tbl
Set idxnew = .CreateIndex("company_id"
idxnew.Fields.Append idxnew.CreateField("company_id"
idxnew.Primary = True
End With
''''
The fields were added ok, but the primary key did not include the company_id, it remained the same as before.
2. I used the below to change the names and size of several fields of another table.
'''edit table group_hm_class
Set tbl = dbs.TableDefs("group_hm_class"
Set fld = dbs.TableDefs("GHGM"
fld.Name = "deduction_id"
fld.Size = 8
Set fld = dbs.TableDefs("name"
fld.Name = "deduction_id"
fld.Size = 30
tbl.Fields.Refresh
''''
The names were changed, but the field sizes remained the same.
Are any of these properties read-only, or is there something I can add to my code to get what I want?
Thanks
'''edit table employee
Set tbl = dbs.TableDefs("employee"
With tbl
.Fields.Append .CreateField("photograph", dbText, 20)
.Fields.Append .CreateField("IsEmployee", dbText, 1)
.Fields.Append .CreateField("salary_group", dbInteger, 2)
.Fields.Append .CreateField("jobcode", dbText, 10)
.Fields.Append .CreateField("jobname", dbText, 20)
.Fields.Append .CreateField("Division", dbText, 30)
.Fields.Append .CreateField("Branch", dbText, 30)
End With
dbs.TableDefs.Append tbl
With tbl
Set idxnew = .CreateIndex("company_id"
idxnew.Fields.Append idxnew.CreateField("company_id"
idxnew.Primary = True
End With
''''
The fields were added ok, but the primary key did not include the company_id, it remained the same as before.
2. I used the below to change the names and size of several fields of another table.
'''edit table group_hm_class
Set tbl = dbs.TableDefs("group_hm_class"
Set fld = dbs.TableDefs("GHGM"
fld.Name = "deduction_id"
fld.Size = 8
Set fld = dbs.TableDefs("name"
fld.Name = "deduction_id"
fld.Size = 30
tbl.Fields.Refresh
''''
The names were changed, but the field sizes remained the same.
Are any of these properties read-only, or is there something I can add to my code to get what I want?
Thanks