Search code examples
vbaexcelibm-midrange

Get decimals from Recordset in VBA with ADODB


I'm trying to get a value from a field, I don't know why is rounded

rs.Open myQuery, cnn
i = 1
Do While rs.EOF = False
    S1 = rs.Fields("S1") 
    Cells(i, 1) = S1
    i = i + 1
    rs.Next
Loop

For example, in the database S1 is 8.567 but I always get 8

Is there a way to define the data type from that field?

Thank you!


Solution

  • I found the solution, in your query you have to define the type of data you want to have.

    sqlQuery = "SELECT CAST(F1 AS DOUBLE) AS newValue FROM TABLE"
    

    Then you will get newValue with decimals.