Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using VB to create new fields in a table 1

Status
Not open for further replies.

skiflyer

Programmer
Sep 24, 2002
2,213
US
I want to do some processing that requires me to create new fields in a whole slew of tables, and rather than going through the design view of each table which would take me hours, I want my VB code to go ahead and just create the field before populating it.

I'm using recordsets to manipulate the table (ADO specifically) if that changes anything.

Thank you,
Rob
 
Here is the general idea using adox.

Function catalogInfo()
'-- set reference to ADOX library
'- Microsoft ADO Ext. 2.6 for DDL and Security
'-- Microsoft ActiveX data objects 2.6 library also needed for ADO

Dim cg As New ADOX.Catalog
Dim tb As New ADOX.Table
Dim cl As ADOX.Column
Set cg.ActiveConnection = CurrentProject.Connection

tb.Name = "Test"
tb.Columns.Append "col1", adInteger
tb.Columns.Append "col2", adVarWChar, 50
''Debug.Print "table = "; cg.Tables("Test").Name
cg.Tables.Append tb

'-rename a column
''Set tb = cg("test")
''Set cl = tb("col2")
''cl.Name = "col2aa"

End Function
 
this is working wonderfully for creating a new table in a db and creating it's fields, however, I'm having trouble modifying it to work with an existing table.... still plugging, but maybe if you beat me to it and know for sure you could let me know?

Thanks,

Rob
 
I always post too soon, got it, much thanks.

-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top