AI Object
 
This macro hands a recordset to the model and asks it to find a pattern in the data. Only the two columns relevant to the question are projected, which keeps the request small.
 
 
Option Explicit
 
Sub Main
    Dim rs As ADODB.Recordset
    Dim aiHnd As Long
 
    SQL.RunRecordset "SELECT TOP 250 * FROM Klanten WITH (READUNCOMMITTED) " & _
                     "WHERE Admin = 1 AND Deleted = 0", _
                     rs, adOpenKeyset, adLockReadOnly, adUseServer
 
    aiHnd = AI.NewConversation(aiGeneral)
    If aiHnd = 0 Then
        MsgBox "NewConversation failed: " & AI.LastErrorMessage, vbCritical
        Exit Sub
    End If
 
    If Not AI.AttachRecordset(aiHnd, rs, "Customers admin 1", _
                              aiRsAllRows, 1000, Array("Postcode", "Plaats")) Then
        MsgBox "AttachRecordset failed: " & AI.LastErrorMessage, vbCritical
        AI.CloseHandle aiHnd
        Exit Sub
    End If
 
    aiHnd = AI.Ask("Which towns have the most customers? Give a top 5.", , aiHnd)
    If aiHnd = 0 Then
        MsgBox "Submit failed: " & AI.LastErrorMessage, vbCritical
        Exit Sub
    End If
 
    Do
        DoEvents
    Loop Until AI.GetStatus(aiHnd) <> 1
 
    If AI.GetStatus(aiHnd) = 2 Then
        MsgBox AI.GetResultStr(aiHnd), vbInformation, "Analysis"
    Else
        MsgBox "Error: " & AI.GetErrorMessage(aiHnd), vbCritical
    End If
 
    AI.CloseHandle aiHnd
    rs.Close
End Sub
 
 
See Also
NewConversationAttachRecordsetAskGetStatusGetResultStr.