function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vstrausbvstrausb 

VB 6.3.error 91 after performing SF Office Toolkit query

I receive a VB error 91, Object variable or With block variable not set after trying to execute the Query command.
 
Here is my code:
 
Option Compare Database
Option Explicit
'Declare an OfficeToolkit object.
'The WithEvents keyword enables asynchronous function calls
Public WithEvents g_sfApi As SForceOfficeToolkitLib3.SForceSession3
Dim MyValue As String
Dim Rectype As String
Dim acctname As String
Dim squery As String
Dim asynch As Boolean
 
Private Sub Form_Load()
Set g_sfApi = New SForceOfficeToolkitLib3.SForceSession3
Form!SFUser.SetFocus
Form!SFUser.Text = " "
Form!SFPassword.Value = " "
End Sub
 
....  Login function here and login is successsful
 
Private Sub Login_to_Salesforce_Click()
SFLogin Username, Password
If g_sfApi.IsLoggedIn Then
     
    Dim Message As String
    Dim Title As String
    Message = "Type in Account name to retrieve"
    Title = "Retrieve Account from SalesForce"
    MyValue = InputBox(Message, Title)
   
    If MyValue > "" Then
        Dim qr As QueryResultSet3
        ' create a session object
        'Set g_sfApi = New SForceOfficeToolkitLib3.SForceSession3
        acctname = MyValue
        Rectype = g_sfApi.EntityNames(0)
        asynch = False
        squery = "Select Id,Name,BillingCity,BillingCountry, BillingState, BillingPostalCode,Fax,Phone FROM " & Rectype & " WHERE Name = '" & MyValue & "'"
        
        SFQuery squery, asynch
        If s.Error <> NO_SF_ERROR Then
           MsgBox s.ErrorMessage
        End If
                   
            For Each v In qr
'loop through the results
'cast to an sobject3 to see more helpful debug info
            Set s = v
            
                If s.Error <> NO_SF_ERROR Then
                    MsgBox s.ErrorMessage
                Else
'use the object
                    MsgBox s.Item(0)
                       
'NOTE you cannot call async methods until this method returns
                End If
            Next
    Else
        Exit Sub
    End If
Else
    If g_sfApi.Error <> NO_SF_ERROR Then
        MsgBox g_sfApi.ErrorMessage
    End If
End If
End Sub

Public Function SFQuery(squery, asynch) As QueryResultSet3
'setup for exception type error handling
On Error GoTo handleError
    SFQuery = g_sfApi.Query(squery, asynch)   <----- Error occurs here
        
    If g_sfApi.Error <> NO_SF_ERROR Then
        MsgBox g_sfApi.ErrorMessage
    End If
    Stop
Exit Function
handleError:
look at the exception message
MsgBox Err.Description
'look at the message in the session
'MsgBox g_sfApi.ErrorMessage
End Function
 
I am not a VB programmer and most of this code was used from information I found on the Web.
Does anyone know why I am receiving a VB error when using the SF Office Toolkit Query command?
Thanks,
 - Vicki
Rob P12Rob P12

Public WithEvents g_sfApi As SForceOfficeToolkitLib3.SForceSession3

I got the same error message. Here is what I did.

Remove the Withevents and change asynch to false

Public  g_sfApi  As  SForceOfficeToolkitLib3.SForceSession3

SFQuery = g_sfApi.Query(squery, False)   <----- Error occurs here -- Change to False

This works in my in my program.

 

Jerry - Trailblazer