CreateObject produces error

R

Robert Chapman

Am trying to automate QMF which accepts OLE automation
through API and have started with IBM's sample code (see
below). It seems to fail at the very first stage with the
line

Set QMFWin = CreateObject("QMFWin.Interface.2")

producing the error - 'ActiveX component can't create
object or return reference to object'. I have checked
Tools:References and tried to select everything
applicable but there is nothing specifically for QMF.

Am using QMF 7.1 and Excel 2000.

Any ideas?

Thx, Robert

Sub Example1()
Dim QMFWin As Object
Dim Result As Variant
Dim ColHeadings As Variant
Dim Cellval As Variant

Set QMFWin = CreateObject("QMFWin.Interface.2")
Stat = QMFWin.InitializeServer("Server1", "", "", True)
If Not (Stat = 0) Then
MsgBox ("InitializeServer Failed. " +
QMFWin.GetLastErrorString())
Exit Sub
End If

QueryID = QMFWin.InitializeQuery(0, "select * from
q.staff")
If QueryID < 0 Then
MsgBox ("InitializeQuery Failed. " +
QMFWin.GetLastErrorString())
Exit Sub
End If
Stat = QMFWin.Open(QueryID, 0, False)
If Not (Stat = 0) Then
MsgBox ("Open Failed. " + QMFWin.GetLastErrorString
())
Exit Sub
End If

Ncolumns = QMFWin.GetColumnCount(QueryID)
Stat = QMFWin.GetColumnHeadings(QueryID, ColHeadings)
If (Stat = 0) Then
RowIndex = 1
ColIndex = 0
For Each strval In ColHeadings
Sheets(1).Cells(RowIndex, ColIndex + 1).Value
= strval
ColIndex = ColIndex + 1
Next
Else
MsgBox ("GetColumnHeadings failed. " +
QMFWin.GetLastErrorString())
Exit Sub
End If

GetNextRow = True
RowIndex = 2
While GetNextRow = True
Stat = QMFWin.FetchNextRow(QueryID, Result)
If (Stat > 0) Then
GetNextRow = False
MsgBox ("FetchNextRow failed. " +
QMFWin.GetLastErrorString())
Exit Sub
ElseIf (stat = -1) Then
' End of result set or empty result set.
GetNextRow = False
If (RowIndex = 2) Then
MsgBox ("Empty result set.")
End If
Else
ColIndex = 1
For Each Cellval In Result
Sheets(1).Cells(RowIndex, ColIndex).Value
= Cellval
ColIndex = ColIndex + 1
Next
RowIndex = RowIndex + 1

End If
Wend

Stat = QMFWin.Close(QueryID)
If Not (Stat = 0) Then
MsgBox ("Close Failed.")
Exit Sub
End If

MsgBox ("Query complete.")
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top