You need to sign in to do that
Don't have an account?
vstrausb
Private Sub Form_Load()
Set g_sfApi = New SForceOfficeToolkitLib3.SForceSession3
End Sub
If g_sfApi.IsLoggedIn Then
DoCmd.Close
DoCmd.OpenForm "Form_Form2"
Else
If g_sfApi.Error <> NO_SF_ERROR Then
Problems logging onto Salesforce from MS Access form
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
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
'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
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
End If
End If
End Sub
Private Sub SF_Password_LostFocus()
Set Password = SFPassword.Value
End Sub
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
Option Explicit
'Changed to public to make available to other forms
Public WithEvents g_sfApi As SForceOfficeToolkitLib3.SForceSession3
On Error GoTo handleError
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
'Changed close of form to hiding of form
Me.Visible = False
DoCmd.OpenForm "Form2"
Else
If g_sfApi.Error <> NO_SF_ERROR Then
MsgBox g_sfApi.ErrorMessage
End If
End If
End Sub
In order to have your API object available to the second form you're launching, I've also change the instantiation of the session object to a public declaration and changed the closing of your login form to making it invisible since closing the form destroys the session object. You'll need to call it by referencing the form, then the session. For example, if your login form is called "Login", then you would reference the API session by calling Forms!Login.g_sfApi.