how to confirm if a field from access is calculate using excel vba

32 Views Asked by At

I'm using the excel vba code below to read datas from Access. is there a command to get if a field is calculate?

I've tried to use the command "schema("Expression")", but the this code doesn't work :( someone could help me with this?

Sub ConnectTooAccess()
    Dim cn As Object
    Dim rs As Object
    Dim sql As String
    
    Set cn = CreateObject("ADODB.Connection")
    
    With cn
        .Provider = "Microsoft.ACE.OLEDB.12.0"
        .Properties("Data Source") = ThisWorkbook.Path & "\DB.accdb"
        .Open
    End With

    sql = "Select * from tbl_DB"
    
    Set rs = CreateObject("ADODB.Recordset")

    With rs
        .ActiveConnection = cn
        .Source = sql
        .CursorType = 1
        .LockType = 2
        .Open
    End With
    

    Dim schema As Object
    Set schema = cn.OpenSchema(4, Array(Empty, Empty, "tbl_DB", "sCalc"))

    While Not schema.EOF
        Debug.Print schema("COLUMN_NAME")
        Debug.Print schema("DATA_TYPE")
        Debug.Print schema("DESCRIPTION")
        Debug.Print schema("Expression")
        schema.MoveNext
    Wend
    
    rs.Close
    cn.Close
    
    Set schema = Nothing
    Set rs = Nothing
    Set cn = Nothing

End Sub
0

There are 0 best solutions below