m m
Technical Support
Example of Using OLE Automation API from VB or VBA
Apr 2, 2013: We are currently rewriting our entire web site. This page may be useful - but is not yet complete and may contain misleading or incomplete information or inoperative links. Please check back soon for the final version. Email support@datablox.com if you have questions.

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:


'----------------------------- 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)
    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