Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old June 27th, 2008, 08:25 PM
mouac01@yahoo.com
Guest
 
Posts: n/a
Default Set field description via ADOX

I can't set the field description property with the code below. I get
the error "Item cannot be found in the collection corresponding to the
requested name or ordinal". Any ideas. TIA...

Sub Test()
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim col As ADOX.Column

Set cat = New Catalog
cat.ActiveConnection = CurrentProject.Connection
Set tbl = New ADOX.Table
With tbl
.Name = g_sTable
'code to get oFlds object not shown
For Each oFld In oFlds.Rows
Set col = New ADOX.Column
col.Name = oFld("FIELDNAME")
'error occurs here
col.Properties("Description").Value = oFld("FIELDTEXT")
.Columns.Append col
Next
End With
cat.Tables.Append tbl
Set col = Nothing
Set tbl = Nothing
Set cat = Nothing
End Sub
  #2  
Old June 27th, 2008, 08:26 PM
The Frog
Guest
 
Posts: n/a
Default Re: Set field description via ADOX

Hi there,

The reason your code hasn't worked is because you need to set the
parentcatalogue property of the column(s) to be the same ADOX
catalogue as the table before you can alter / add any property
definitions. Give this a try:

Sub Test()

Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table

Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection
Set tbl = New ADOX.Table

With tbl
.Name = g_sTable

'code to get oFlds object not shown

For Each oFld In oFlds.Rows
.columns.append "Insert Name of Column Here", columntype
here
with tbl.columns("Insert Name of Column Here")
set .ParentCatalog = cat
.Properties("Description") = "This is a test"
.Properties("Autoincrement") = true
' and just keep adding the bits you need
end with
Next
End With

cat.Tables.Append tbl

'cleanup
set tbl = nothing
set cat = nothing

end sub

I just 'aircoded' this and havent had a chance to test the actual code
out so please check it for typo's. Basically you can see how the
properties are added once the .ParentCatalog is set for the column.
Once that is done you should'nt have any troubles.

Cheers

The Frog
  #3  
Old June 27th, 2008, 08:26 PM
mouac01@yahoo.com
Guest
 
Posts: n/a
Default Re: Set field description via ADOX

Wow! I just needed 1 line of code to set the column ParentCatalog
like you said. Thanks...
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles