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

problems using code to find primary keys....idx.Primary

Status
Not open for further replies.

notageek7

Technical User
Jan 23, 2004
54
US
I've got a project that pulls out tables, fields, indexed fields, and primary keys from a chosen database. I've got most working but am having some problems with my primary keys. I'm not sure how to access my primary key. One example is in my table CheckRequest the primary key is CheckReqKey. In my loop below when idx.Name is CheckReqKey, the primary key, it isn't recognized. It is only when idx.Name is "PrimaryKey" that idx.Primary is true. In my debug window I can expand out idx and find that when idx.Name is "PrimaryKey" by continuing to expand I find that idx-fields-item1 has a value name which equals CheckReqKey. My problem is this logically makes sense but is there a way to access this value in my code?
I tried: idx.Fields.Item1.Name with no luck??? Please help if you have experience with indexes. Thanks in advance!!!

For Each idx In tblT.Indexes
If idx.Primary Then
Debug.Print idx.Name, idx.Foreign, idx.Primary, idx.Unique, idx.Required
indexName = idx.Primary
If Not idx.Name = "PrimaryKey" Then
Form_frmDatabaseInfo.cbxPrimaryKey.Value = idx.Name
End If
End If
Next idx
 
Something like this ?
For i = 0 To idx.Fields.Count - 1
Debug.Print idx.Fields(i).Name
Next i

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks for trying but idx.Fields(i).Name dosn't have any value....
 
And this ?
For i = 0 To idx.Fields.Count - 1
Debug.Print idx.Fields(i).Name
For Each p In idx.Fields(i).Properties
On Error Resume Next
Debug.Print " " & p.Name & " = " & p.Value
On Error GoTo 0
Next p
Next i

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks for trying but p.Name isn't recognized, assuming p is dim p as properties....
 
nothing appears to be recognized after idx.fields. , anything i type in after this beginning dosn't give me a drop down list of possible values
 
Dim i As Long, p As Property

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
i declared p as properties was the problem....now it compiles but dosn't do anything...it hits your code and drops right on by
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top