![]() |
![]() |
Technical Support
|
![]() |
Following is a very simple example of using OfficeQ's OLE Automation API from VB or VBA.
The block below shows a simple example of using OLE Automation to run OfficeQ6 and extract data. The example is not a complete program - but it does use all of the API calls normally needed.
It performs the following tasks:
...reference...
'----------------------------- OLE Automation VB Example ------------------------------ ' ' program needs 'reference' to OfficeQ6 - but no include file ' Dim nRecType&, nIndex&, nCount&, nErr&, sAllFields$, sValue$ Dim qbs As OfficeQ6.Reader '--- qbs name is arbitrary, but makes code simple to edit '--- ole object - dim and create Set qbs = CreateObject("OfficeQ6.Reader") '--- read the file nErr = qbs.ReadFile(sQbwFile, '') If nErr <> 0 Then '...respond to error '--- get record with known key (index not needed) nErr = qbs.RecordK(QBR_Settings, 2, sAllFields) sValue = qbs.FieldV(sAllFields, "sVersionHex") '--- do something with sValue .... '--- get count of records then get each record nCount = qbs.RecordCount(QBR_Account) If nCount > 0 Then For nIndex = 0 To nCount - 1 '--- get record at 0 based index (key not needed) nErr = qbs.RecordN(nRecType, nIndex, sAllFields) Next End If End If nErr = qbs.Done() Set qbw = Nothing 'Note that this line is VERY IMPORTANT 'It is what causes the program to disconnect from 'the OfficeQ6 module and remove OfficeQ6 from memory