' Open the VBS Global Script Editor in WInCC Explorer ' Open the SQL FUnctions module, then paste this as a function to the ' end of the file. Then save. '--------------------------------------------------------------------------- ' UpdateDBGrid ' Uses Microsoft MSHFlexGrid control to visualize DB Data Function UpdateDBGrid (screenName, dbGridControlName, strSql) ' Load MSHFlexGrid Control ' create and initialize variables Dim objConnection : Set objConnection = CreateObject("ADODB.Connection") Dim objRecordset : Set objRecordset = CreateObject("ADODB.Recordset") objConnection.ConnectionString = gStrConn ' disable automatic error reporting so we can handle in script On Error Resume Next ' Open ADO Connection objConnection.Open ' Check for ADO Connection error. 0 = No Errors. If Err.Number = 0 Then ' 2. execute SQL Command and store results in RecordSet object objRecordset.Open strSql, objConnection, 3 ' Check for ADO RecordSet error. If Err.Number = 0 Then If (objRecordset.RecordCount > 0) Then ' make sure we have at least 1 record returned. ' set to DataGrid Dim dg : Set dg = HMIRuntime.Screens(screenName).ScreenItems(dbGridControlName) ' use with to set object properties With dg .DataSource = objRecordset .Refresh .ColWidth(0) = 800 .ColWidth(1) = 1000 .ColWidth(2) = 1000 .ColWidth(3) = 850 End With Else HMIRuntime.Trace "Selection returned no fields" & vbNewLine End If End If ' End of RecordSet Error check End If 'End of connection error Check ' check for any error If Err.Number <> 0 Then HMIRuntime.Trace "UpdateDBGrid() Error exists:" & vbCrlf & "[" & Err.Number & "] [" & Err.Source & "] " & Err.Description & vbCrlf '(Give details about the Error) ' log error to log file Dim results : results = logError("UpdateDBGrid()[" & screenName & "." & dbGridControlName & "]",Err.Number, Err.Source, Err.Description) Err.Clear '(Will Clear the Error) End If ' 4. Close and delete ADO Objects. Set dg = Nothing objRecordset.Close objConnection.Close Set objRecordset = Nothing Set objConnection = Nothing End Function '-----------------------------------------------------------------------------------------------------------------------------