AI Object
 
Syntax
 
AI.AttachRecordset(Handle As Long, rs As Object, [Caption As String], [Scope As AIRecordsetScope], [MaxRows As Long], [Columns As Variant]) As Boolean
 
Description
Attaches the data of an ADODB recordset to a conversation handle, so the model can analyse it. The recordset is serialised at the moment of the call — a snapshot, independent of the cursor position and of the query that produced it. The cursor of the macro's own recordset is left untouched.
 
Call this before Ask, on a handle from NewConversation. The return value is True on success, or False on a validation error.
 
At most one recordset may be attached per handle. A second call on the same handle fails with aiErrInvalidRequest. A handle may carry both files and one recordset at the same time.
 
Parameter
Description
Handle
Long, a handle created with NewConversation.
rs
Object, an open ADODB recordset.
Caption
String, optional. A short description of the dataset.
Scope
AIRecordsetScope, optional. Selects which rows are sent:
Constant
Value
Meaning
aiRsCurrentRow
0
Only the current record.
aiRsAllRows
1
All rows, up to MaxRows. Default.
MaxRows
Long, optional. Maximum number of rows to send. Default 1000. Serialisation also stops earlier if an internal size limit is reached; in that case the dataset is marked as truncated.
Columns
Variant, optional. An array of column names to send. When omitted, all columns are sent (binary columns excluded). When supplied, only the named columns are sent, in the given order. An unknown column name fails the call with aiErrInvalidRequest. Use Array("Col1", "Col2") to build the value.
 
Note. The Columns argument is a projection for analysis, not a filter. It selects which columns the model sees; it does not select which rows are sent. To restrict rows, filter the recordset (or its query) before attaching it.
 
See Also
NewConversationAttachFileClearAttachmentsAsk.
Example
 
Dim rs As ADODB.Recordset
SQL.RunRecordset "SELECT * FROM Relaties WITH (READUNCOMMITTED) " & _
                 "WHERE Admin = 1 AND Soort = 'K'", _
                 rs, adOpenKeyset, adLockReadOnly, adUseServer
 
Dim aiHnd As Long
aiHnd = AI.NewConversation(aiGeneral)
If AI.AttachRecordset(aiHnd, rs, "Customers admin 1", aiRsAllRows, 1000, _
                      Array("Postcode", "Plaats")) Then
    aiHnd = AI.Ask("Which towns have the most customers? Give a top 5.", , aiHnd)
End If