Hello Team,
I would like to ask you, whats wrong in this script. This script works fine for several months and now appears this error.
Thank you very much for your support.
I would like to ask you, whats wrong in this script. This script works fine for several months and now appears this error.
VBA Code:
Sub neco()
Timestamp_CycleStart = CStr(Cells(ActiveCell.Row, 2).Value)
Timestamp_CycleStop = CStr(Cells(ActiveCell.Row, 5).Value)
time_rset_sql_start = Format(Timestamp_CycleStart, "hh:mm:ss")
date_rset_sql_start = Format(Timestamp_CycleStart, "yyyy")
date_rset_sql_start = date_rset_sql_start & "-" & Format(Timestamp_CycleStart, "mm")
date_rset_sql_start = date_rset_sql_start & "-" & Format(Timestamp_CycleStart, "dd")
Timestamp_rset_sql_start = date_rset_sql_start & " " & time_rset_sql_start
time_rset_sql_Stop = Format(Timestamp_CycleStop, "hh:mm:ss")
date_rset_sql_Stop = Format(Timestamp_CycleStop, "yyyy")
date_rset_sql_Stop = date_rset_sql_Stop & "-" & Format(Timestamp_CycleStop, "mm")
date_rset_sql_Stop = date_rset_sql_Stop & "-" & Format(Timestamp_CycleStop, "dd")
Timestamp_rset_sql_Stop = date_rset_sql_Stop & " " & time_rset_sql_Stop
Dim qt As QueryTable
connstring = "ODBC;DSN=CIMPLICITY Logging - POINTS;UID=hmi;PWD=;DATABASE=CIMPLICITY"
'SQL Dotaz
Par01 = "DATA_10SEC.TC5_3_PV_VAL0 AS P1_TC5_3Z"
Par02 = "DATA_10SEC.TC5_2_PV_VAL0 AS P1_TC5_2P"
Par03 = "DATA_10SEC.TC5_1_PV_VAL0 AS P1_TC5_1P"
Par04 = "DATA_10SEC.TC4_1_PV_VAL0 AS P1_TC4_1P"
Par05 = "DATA_10SEC.TC4_3_PV_VAL0 AS P1_TC4_3Z"
Par06 = "DATA_10SEC.TC4_2_PV_VAL0 AS P1_TC4_2Z"
Par07 = "DATA_10SEC.TC4_4_PV_VAL0 AS P1_TC4_4P"
Par08 = "DATA_10SEC.TC7_2_PV_VAL0 AS P2_TC7_2Z"
Par09 = "DATA_10SEC.TC7_1_PV_VAL0 AS P2_TC7_1P"
Par10 = "DATA_10SEC.TC6_4_PV_VAL0 AS P2_TC6_4P"
Par11 = "DATA_10SEC.TC6_3_PV_VAL0 AS P2_TC6_3P"
Par12 = "DATA_10SEC.TC6_2_PV_VAL0 AS P2_TC6_2Z"
Par13 = "DATA_10SEC.TC6_1_PV_VAL0 AS P2_TC6_1Z"
Par14 = "DATA_10SEC.TC5_4_PV_VAL0 AS P2_TC5_4P"
Par15 = "DATA_10SEC.TC9_1_PV_VAL0 AS P3_TC9_1Z"
Par16 = "DATA_10SEC.TC8_4_PV_VAL0 AS P3_TC8_4P"
Par17 = "DATA_10SEC.TC8_3_PV_VAL0 AS P3_TC8_3P"
Par18 = "DATA_10SEC.TC8_2_PV_VAL0 AS P3_TC8_2P"
Par19 = "DATA_10SEC.TC8_1_PV_VAL0 AS P3_TC8_1Z"
Par20 = "DATA_10SEC.TC7_4_PV_VAL0 AS P3_TC7_4Z"
Par21 = "DATA_10SEC.TC7_3_PV_VAL0 AS P3_TC7_3P"
Par22 = "DATA_10SEC.TC10_4_PV_VAL0 AS P4_TC10_4Z"
Par23 = "DATA_10SEC.TC10_3_PV_VAL0 AS P4_TC10_3P"
Par24 = "DATA_10SEC.TC10_2_PV_VAL0 AS P4_TC10_2P"
Par25 = "DATA_10SEC.TC10_1_PV_VAL0 AS P4_TC10_1P"
Par26 = "DATA_10SEC.TC9_4_PV_VAL0 AS P4_TC9_4Z"
Par27 = "DATA_10SEC.TC9_3_PV_VAL0 AS P4_TC9_3Z"
Par28 = "DATA_10SEC.TC9_2_PV_VAL0 AS P4_TC9_2P"
Par29 = "DATA_10SEC.TC12_3_PV_VAL0 AS P5_TC12_3Z"
Par30 = "DATA_10SEC.TC12_2_PV_VAL0 AS P5_TC12_2P"
Par31 = "DATA_10SEC.TC12_1_PV_VAL0 AS P5_TC12_1P"
Par32 = "DATA_10SEC.TC11_4_PV_VAL0 AS P5_TC11_4P"
Par33 = "DATA_10SEC.TC11_3_PV_VAL0 AS P5_TC11_3Z"
Par34 = "DATA_10SEC.TC11_2_PV_VAL0 AS P5_TC11_2Z"
Par35 = "DATA_10SEC.TC11_1_PV_VAL0 AS P5_TC11_1P"
Par36 = "DATA_10SEC.SP13_1_PV_VAL0 AS Tlak"
Par37 = "DATA_10SEC.Sum_CV_VAL0 AS Teplota"
Par38 = "DATA_10SEC.CycleStep03_VAL0 AS ShowTime"
sqlstring = ("SELECT DATA_10SEC.Timestamp, " _
& Par38 & "," & Par37 & "," & Par36 & "," _
& Par01 & "," & Par02 & "," & Par03 & "," & Par04 & "," & Par05 & "," & Par06 & "," & Par07 & "," _
& Par08 & "," & Par09 & "," & Par10 & "," & Par11 & "," & Par12 & "," & Par13 & "," & Par14 & "," _
& Par15 & "," & Par16 & "," & Par17 & "," & Par18 & "," & Par19 & "," & Par20 & "," & Par21 & "," _
& Par22 & "," & Par23 & "," & Par24 & "," & Par25 & "," & Par26 & "," & Par27 & "," & Par28 & "," _
& Par29 & "," & Par30 & "," & Par31 & "," & Par32 & "," & Par33 & "," & Par34 & "," & Par35 & " FROM DATA_10SEC WHERE DATA_10SEC.timestamp BETWEEN '" _
& Timestamp_rset_sql_start & "' AND '" & Timestamp_rset_sql_Stop & "' ORDER BY DATA_10SEC.timestamp ASC")
Set qt = QueryTableByName("mtable", Worksheets("Data_DB"))
If qt Is Nothing Then
Set qt = ActiveSheet.QueryTables.Add(Connection:=connstring, Destination:=Worksheets("Data_DB").Range("A3"), Sql:=sqlstring)
qt.Name = "mtable"
Else
qt.CommandText = sqlstring
End If
qt.Refresh
End Sub
Thank you very much for your support.
Last edited by a moderator: