I have an AI designed macro that is supposed to read the ID value of a listbox tied to a Reports Table and then opens the report named using the ID.
It gets A Basic Runtime Error Property or Method Not Found. Value
It highlights a line - nID = oListBox.Value
The Bound Value is set to 1, where ID is located.
Can this macro work?
Here is the macro:
Sub OpenReportByID(oEvent As Object)
Dim oForm As Object
Dim oListBox As Object
Dim nID As Long
Dim sReportName As String
Dim oConnection As Object
Dim oStatement As Object
Dim oResult As Object
Dim oReportDoc As Object
' Get the form that triggered the event'
oForm = oEvent.Source.Model.Parent
' Get the ListBox control'
oListBox = oForm.getByName("lstReports") ' Change to your ListBox name'
' Get the selected ID (bound value)'
nID = oListBox.Value
If nID > 0 Then
' Connect to the database'
oConnection = ThisDatabaseDocument.CurrentController.ActiveConnection
If IsNull(oConnection) Then
ThisDatabaseDocument.CurrentController.connect
oConnection = ThisDatabaseDocument.CurrentController.ActiveConnection
End If
' Create SQL to get the report name'
oStatement = oConnection.createStatement
oResult = oStatement.executeQuery("SELECT ""ReportName"" FROM ""Reports Table"" WHERE ""ID"" = " & nID)
If oResult.next Then
sReportName = oResult.getString(1)
' Open the report'
oReportDoc = ThisDatabaseDocument.ReportDocuments.getByName(sReportName)
oReportDoc.open
Else
MsgBox "No report found for this ID."
End If
Else
MsgBox "Please select a valid report."
End If
End Sub

but first of all I would install MRI.

