I am using a VBA to query and fill a query table with data from another excel workbook. I am having problems with a field name Hours which is defined as a number with 2 decimal places in both workbooks. When I use the sum function on that particular column it always sums at 0.00. It is as if the cells are being seen as text instead of numbers. Any ideas?
This is a piece of my code:
bdate = Range("begin").Value
edate = Range("end").Value
fdate = 1 / 1 / 2009
Sheets("Calc SP").Select
Application.Goto Reference:="CalcSPClearArea"
Selection.ClearContents
wherestatus = " AND ((`Query_from_fipe109#ffdc`.STATUS IN ('COMPLETE', 'AWAIT ADDS') AND `Query_from_fipe109#ffdc`.STATUS_DATE Between #" & bdate & "#" & " And #" & edate & "#)"
orstatus = " OR (`Query_from_fipe109#ffdc`.STATUS IN ('IN PROCESS') AND `Query_from_fipe109#ffdc`.STATUS_DATE Between #" & fdate & "#" & " And #" & edate & "#));"
wherejobtype = " where `Query_from_fipe109#ffdc`.JOB_TYPE = 17"
Set cnn = New ADODB.Connection
Set cmd = New ADODB.Command
Set rs = New ADODB.Recordset
strDbPath = "I:\Map_Folders\NZ170Y\Metrics\Reporting\CurrentData.xlsx"
cnn.ConnectionString = "Provider=Microsoft.Ace.OLEDB.12.0;" & "Data Source=" & strDbPath & ";" & "Extended Properties=""Excel 12.0 Xml;HDR=Yes;"""
cnn.Open
Set cmd.ActiveConnection = cnn
cmd.CommandText = "Select `Query_from_fipe109#ffdc`.JOB_NO AS JOB_NO, `Query_from_fipe109#ffdc`.CLIENT AS CLIENT, `Query_from_fipe109#ffdc`.HOURS_WRKD AS HOURS, `Query_from_fipe109#ffdc`.CLLI AS CLLI,`Query_from_fipe109#ffdc`.OPERATOR_ID AS OPERATOR, `Query_from_fipe109#ffdc`.STATUS AS STATUS from `I:\Map_Folders\NZ170Y\Metrics\Reporting\CurrentData.xlsx`.`Query_from_fipe109#ffdc`" & wherejobtype & wherestatus & orstatus
Set rs = cmd.Execute
Set qt = ActiveSheet.QueryTables.Add(Connection:=rs, Destination:=ActiveSheet.Range("A13"))
qt.Refresh
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing