Applies to:
Versions of PcVue supporting VBA and the Grid control. |
||
|
||
Summary:
How to display SQL Server trend table values in a grid control. With minor modifications this example could be used with a log table or even a custom (non PcVue) table. Note that you could alternatively use an SQL Server View (instead of a table) to customise the content. For example, replacing the chrono value with a user friendly timestamp. See article KB492. |
||
|
||
Details:
1. Create a mimic containing a grid control. Find the name of the grid using the Graphic Explorer. The default is AIGrid1.2. Insert the following VBA code in the Mimic_Open event for the mimic. Public oCnx As New ADODB.Connection Private Sub Mimic_Open() On Error GoTo eOnError ‘Customize your connection string ‘Open connection ‘Send SQL Request ‘Read answer and populate AIGrid1 rows While oRec.EOF = False oRec.MoveNext ‘Close connection oCnx.Close Exit Sub eOnError: End Sub 3. Using the VBA Editor add the Microsoft ActiveX DataObjects 6.0 Library reference to the mimic. 4. Customize the connection string in the VBA script. If you don’t know the string you can use the following trick to find it. a. Create a text file (.txt) and change its extension to .udl. 5. Save and execute the VBA script by closing and opening the mimic. If everything works it might look something like this. 6. Remember that you can request and manipulate data before you insert it in the grid. For example: Truncate result Change the field order Request an SQL Server view Request using a WHERE clause |
||
|
||
Sample project:KB838.zip. The project was created with PcVue 11.2 and uses SQL Server 2014 Express Edition. The server instance is SQLEXPRESS. You must edit the connection string in the Application Explorer (Archives.Databases.DATABASE1) to suit the installation on the target PC.Download attachments: KB838.zip | ||
|
||
|
Created on: 05 Oct 2016 Last update: 04 Sep 2024