Wednesday, April 26 2006: OpenSchema
I know I'm about 5 years behind the times, but I've recently started playing with the OpenSchema() method of the ADODB.Connection object. You can get at a lot of useful information that way. For example, when importing data, you can read the ForeignKeys schema to figure out the order data needs to be loaded to avoid violating key constraints or get at extended properties, like column descriptions.
Public Function GetColumnDescription(cnn As ADODB.Connection, sTableName As String,
sColumnName As String) As String
Dim rs As ADODB.Recordset
Dim sDescr As String
' Init description
sDescr = ""
Set rs = cnn.OpenSchema(adSchemaColumns)
With rs
.Filter = "TABLE_NAME='" & sTableName & "' AND COLUMN_NAME='" & sColumnName & "'"
If .RecordCount <> 0 Then
If Not IsBlank(.Fields("DESCRIPTION")) Then
sDescr = CStr(.Fields("DESCRIPTION").Value)
End If
End If
.Filter = adFilterNone
.Close
End With
Set rs = Nothing
' Return description
GetColumnDescription = sDescr
End Function