You need to sign in to do that
Don't have an account?
vstrausb
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
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
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
Dim asynch As Boolean
Private Sub Form_Load()
Set g_sfApi = New SForceOfficeToolkitLib3.SForceSession3
Form!SFUser.SetFocus
Form!SFUser.Text = " "
Form!SFPassword.Value = " "
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
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"
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
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 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
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
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