定义一个记录集变量。 
DIM SC AS RECORDSET
debug.print sc.fields.count
就可以了。

解决方案 »

  1.   

    Dim adoConnectionX As New ADODB.Connection
    'Ms SQL 7:
    'adoConnectionX.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Data Source=yuer;DataBase=Northwind"
    'Access 2000:
    adoConnectionX.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\NWind2K.mdb;Persist Security Info=False"
    Dim adoxCatalogX As New ADOX.Catalog
    Set adoxCatalogX.ActiveConnection = adoConnectionX
    Dim i As Integer
    Dim j As Integer
    For i = 0 To adoxCatalogX.Tables.Count - 1
        If adoxCatalogX.Tables.Item(i).Type = "TABLE" Then
           Debug.Print "[" & adoxCatalogX.Tables.Item(i).Name & "] Contains " & adoxCatalogX.Tables.Item(i).Columns.Count & " Fields!"
           For j = 0 To adoxCatalogX.Tables.Item(i).Columns.Count - 1
               Debug.Print "[" & adoxCatalogX.Tables.Item(i).Name & "].[" & adoxCatalogX.Tables.Item(i).Columns.Item(j).Name & "]"
           Next j
        End If
    Next i
      

  2.   

    playyuer 补充:引用 Microsoft ADO Extensions 2.x for DDL and Security (ADOX)
      

  3.   

    SQL SERVER 执行
    select * from syscolumns where id=object_id('tablename')
      

  4.   

    select * from syscolumns where id=object_id('tablename')