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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

renaming a table field with ADO

Status
Not open for further replies.

pgwebece7

Programmer
Apr 24, 2004
7
RO
Is it possible to rename a database table field
using either ADO objects or Jet SQL ?
 
Example using ADOX.
'-- 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 cn As adodb.Connection
Dim cl As ADOX.Column
Set cg.ActiveConnection = CurrentProject.Connection

'- create a test table.
tb.Name = "Test"
tb.Columns.Append "col1", adInteger
tb.Columns.Append "col2aa", adVarWChar, 50
Debug.Print "table = "; cg.Tables("Test").Name
cg.Tables.Append tb
'' modify the test table.
'-rename a column
Set tb = cg("test")
Set cl = tb("col2aa")
Debug.Print cl
'- modify a property of the column.
cl.Properties("Jet OLEDB:Allow Zero Length") = True
cl.Name = "col2bb"
Debug.Print cl
 
Sorry,my internet is dial-up and I was In hurry.
I forgot to mention I need a C++ code and with ACCESS *mdb files.
 
Set up a connection string to the Access.mdb from your program.

replace this with your connection.
Set cg.ActiveConnection = CurrentProject.Connection

Dim connString As String
Dim cn As New ADODB.Connection
connString = "provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=\\someserver\somedirectory\yourmdb.mdb;" & _
"Persist Security Info=False"
cn.ConnectionString = connString
cn.Open connString
Set cg.ActiveConnection = cn

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top