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

Using ADO to set field as index (key)? 1

Status
Not open for further replies.

Dan01

Programmer
Jun 14, 2001
439
0
0
US
Is it possible to use ADO in to set a field as a key? Thanks, Dan.
 
I believe so, but you will need to iterate through the properties collection of the table to find the correct property name to set the primary key. Here is a function with some code commented out that you could modify. You will need an adox library reference.


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 cn As adodb.Connection
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
''Exit Function
'-rename a column
''Set tb = cg("test")
''Set cl = tb("col2aa")
''Debug.Print cl
''Set zero length property on col2aa.
''cl.Properties("Jet OLEDB:Allow Zero Length") = True
''cl.Name = "col2aa"

Set tb = cg.Tables("Categorys")
Debug.Print "table name = "; tb.Name

'- Iterate the property collection.
Dim pp As Property
For Each cl In tb.Columns
Debug.Print "name = "; cl.Name
Debug.Print "type = "; cl.Type
For Each pp In cl.Properties
Debug.Print "property name = "; pp.Name
Debug.Print "property value = "; pp.Value

Next
Next

End Function
 
Thanks cmmrfrds. This code will be quite helpful. Dan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top