Set field description via ADOX

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mouac01@yahoo.com

    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.ActiveConne ction = 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.Appe nd tbl
    Set col = Nothing
    Set tbl = Nothing
    Set cat = Nothing
    End Sub
  • The Frog

    #2
    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.ActiveConne ction = 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("In sert Name of Column Here")
    set .ParentCatalog = cat
    .Properties("De scription") = "This is a test"
    .Properties("Au toincrement") = true
    ' and just keep adding the bits you need
    end with
    Next
    End With

    cat.Tables.Appe nd 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

    Comment

    • mouac01@yahoo.com

      #3
      Re: Set field description via ADOX

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

      Comment

      Working...