Applies to:
All VBA versions
Summary:
This VBA module allows to send read and write requests to a SQL Server database, using the ADO VBA Reference. The script is embbeded in a mimic created with PcVue 10, but can be pasted in any PcVue VBA versions.
To use this script, you must adapt the five “connection parameters” here below, according to your SQL Server connection.
The VBA reference used is : Microsoft ActiveX Data Objects 2.7 Libray
Details:
Option Explicit
‘************************************************************************************* ‘——————— ‘To switch to SQL Server authentification (use of cLogin and cPwd) ‘———————————————– ‘Connections objets |
‘************************************************************************************* ‘************************************************************************************* ‘———————————————– If Connection = True Then End Sub |
‘************************************************************************************* ‘************************************************************************************* ‘———————————————– On Error GoTo TRAP_Error ‘Connection string for SQL Server ‘Authentification ‘Open connection ‘Return of function TRAP_Error: ‘Close connection if it exists ‘Return of function ‘———————————————- |
‘************************************************************************************* ‘************************************************************************************* ‘————————————————– Dim iNbRow As Integer ‘Number of resulted records On Error GoTo TRAP_Error ‘Connection must be opened ‘Send request ‘If there are any records iNbRow = oRst.RecordCount – 1 ‘Number of records (rows) ‘set result table with good limits oRst.MoveFirst ‘Pointer on the 1st record While Not oRst.EOF ‘Parse all records If (Not oRst.Fields(iCurrCol).Value = “NULL”) Then ‘If data is not NULL => insert in result table ‘Next record (DB request result) + next row (result table) ‘Close recordset if necessary ‘Set return Else Exit Function TRAP_Error: ‘————————————————– On Error GoTo TRAP_Error ‘Connection must be opened ‘Send request ‘Close recordset if necessary SendCommand = True Exit Function TRAP_Error: Download attachments: Mimic_PcVue10 |
Created on: 26 Sep 2014 Last update: 26 Aug 2024