b3cf
asked on
How to create Access tables and relationships using VB
Hi
Could someone advice me how I could create MS Access
tables and relationships using VB. I need to specify
the indexes and whether the field is required and whether to allow zero length too. Need to define primary keys with
auto number and without auto number. If I can use ADO that will be great.
Any help is greatly appreciated.
Thanks
Could someone advice me how I could create MS Access
tables and relationships using VB. I need to specify
the indexes and whether the field is required and whether to allow zero length too. Need to define primary keys with
auto number and without auto number. If I can use ADO that will be great.
Any help is greatly appreciated.
Thanks
Use the 'CREATE TABLE' command, have a look in the help text for the syntax.
You can achieve all of this with the ADOX object model.
Anthony
Anthony
Here is an example to create a new table using ADOX:
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Set cat = New ADOX.Catalog
With cat
.ActiveConnection = "Provider=Microsoft.Jet.OL EDB.4.0;Da ta Source=c:\temp\db1.mdb"
Set tbl = New ADOX.Table
With tbl
.Name = "Table1"
.Columns.Append "ID", adInteger
.Columns.Append "Description", adVarWChar, 50
.Columns.Append "Created", adDate
End With
.Tables.Append tbl
End With
Set tbl = Nothing
Set cat = Nothing
Anthony
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Set cat = New ADOX.Catalog
With cat
.ActiveConnection = "Provider=Microsoft.Jet.OL
Set tbl = New ADOX.Table
With tbl
.Name = "Table1"
.Columns.Append "ID", adInteger
.Columns.Append "Description", adVarWChar, 50
.Columns.Append "Created", adDate
End With
.Tables.Append tbl
End With
Set tbl = Nothing
Set cat = Nothing
Anthony
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great. Thanx alot Dannic and others who contributed.