• vstrausb
  • NEWBIE
  • 0 Points
  • Member since 2006

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
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
I have a form in MS Access for input of username and password.  If the login is successful, another form is opened to retrieve a record from Salesforce.  I do not receive an error message that the login failed and the form2 does not open.
 
Here is the procedural code:
 
Option Compare Database
Option Explicit
'Declare an OfficeToolkit object.
'The WithEvents keyword enables asynchronous function calls
Dim WithEvents g_sfApi As SForceOfficeToolkitLib3.SForceSession3
Public Username As Object
Public Password As Object
 Public Function SFLogin(Username As Object, Password As Object) As Boolean
'setup for exception type error handling
On Error GoTo handleError
' create a session object
    Set g_sfApi = New SForceOfficeToolkitLib3.SForceSession3
' make a login call
    SFLogin = g_sfApi.Login(Username, Password)
 
If g_sfApi.Error <> NO_SF_ERROR Then
MsgBox g_sfApi.ErrorMessage
Exit Function
End If
Exit Function
handleError:
'look at the exception message
MsgBox Err.Description
'look at the message in the session
MsgBox g_sfApi.ErrorMessage
End Function

Private Sub Form_Load()
Set g_sfApi = New SForceOfficeToolkitLib3.SForceSession3
End Sub
Private Sub Login_to_Salesforce_Click()

If g_sfApi.IsLoggedIn Then
 DoCmd.Close
 DoCmd.OpenForm "Form_Form2"
Else
If g_sfApi.Error <> NO_SF_ERROR Then
MsgBox g_sfApi.ErrorMessage
End If
End If
End Sub
Private Sub SF_Password_LostFocus()
Set Password = SFPassword.Value
End Sub
Private Sub SF_User_Name_LostFocus()
Set Username = SFUser.Value
End Sub
Any ideas why form2 is not opening?  How can I determine if loggin is successful?
Thanks,
 - Vicki
I have a form in MS Access for input of username and password.  If the login is successful, another form is opened to retrieve a record from Salesforce.  I do not receive an error message that the login failed and the form2 does not open.
 
Here is the procedural code:
 
Option Compare Database
Option Explicit
'Declare an OfficeToolkit object.
'The WithEvents keyword enables asynchronous function calls
Dim WithEvents g_sfApi As SForceOfficeToolkitLib3.SForceSession3
Public Username As Object
Public Password As Object
 Public Function SFLogin(Username As Object, Password As Object) As Boolean
'setup for exception type error handling
On Error GoTo handleError
' create a session object
    Set g_sfApi = New SForceOfficeToolkitLib3.SForceSession3
' make a login call
    SFLogin = g_sfApi.Login(Username, Password)
 
If g_sfApi.Error <> NO_SF_ERROR Then
MsgBox g_sfApi.ErrorMessage
Exit Function
End If
Exit Function
handleError:
'look at the exception message
MsgBox Err.Description
'look at the message in the session
MsgBox g_sfApi.ErrorMessage
End Function

Private Sub Form_Load()
Set g_sfApi = New SForceOfficeToolkitLib3.SForceSession3
End Sub
Private Sub Login_to_Salesforce_Click()

If g_sfApi.IsLoggedIn Then
 DoCmd.Close
 DoCmd.OpenForm "Form_Form2"
Else
If g_sfApi.Error <> NO_SF_ERROR Then
MsgBox g_sfApi.ErrorMessage
End If
End If
End Sub
Private Sub SF_Password_LostFocus()
Set Password = SFPassword.Value
End Sub
Private Sub SF_User_Name_LostFocus()
Set Username = SFUser.Value
End Sub
Any ideas why form2 is not opening?  How can I determine if loggin is successful?
Thanks,
 - Vicki