Salesforce SOQL from Microsoft Office

The Salesforce ODBC Driver extends the number of applications that you can use Salesforce SOQL from.

To get started:

Before you can use the Salesforce.com ODBC Driver to connect your application to Salesforce.com, you need to configure an ODBC data source. An ODBC data source stores the connection details for the target database (e.g. Salesforce.com) and the ODBC driver that is required to connect to it (e.g. the Salesforce.com ODBC driver).

To run ODBC Administrator (which you use to create a data source), in the Windows Run dialog box, type this command if you are using a 64-bit version of Microsoft Office:

%windir%\system32\odbcad32.exe

–Or–

Type this command if you are using a 32-bit version of Microsoft Office:

%windir%\syswow64\odbcad32.exe

If you are not sure whether your version of Microsoft Office is 32-bit or 64-bit, start an Office application e.g. Microsoft Access, and then look for the application's process in Task Manager. If the process name is (for Microsoft Access) MSACCESS.EXE *32, Microsoft Office is 32-bit. If the process name is MSACCESS.EXE, Microsoft Office is 64-bit.

To create a Salesforce.com ODBC Driver data source:

  1. In the 32-bit version of ODBC Administrator, choose the System DSN tab, and then choose Add.

    To run the 32-bit version of ODBC Administrator, in the Windows Run dialog box, enter:

    %windir%\syswow64\odbcad32.exe
  2. In the Create New Data Source dialog box, choose Easysoft Salesforce SOQL ODBC Driver, and then choose Finish.
  3. Complete the Easysoft Salesforce SOQL ODBC Driver DSN Setup dialog box:
    Setting Value
    DSN Salesforce.com
    User Name The name of your Salesforce.com user. For example, myuser@mydomain.com.
    Password The password for your Salesforce.com user.
    Token The security token for your Salesforce.com user, if required.

    To find out whether you need to supply a security token, choose the Test button. If the connection attempt fails with an error which contains LOGIN_MUST_USE_SECURITY_TOKEN, you need to supply one.

    Salesforce.com emails the security token to the email address associated with your Salesforce.com user account. If you have not received a security token, you can regenerate it. Salesforce.com will then email the new security token to you. To regenerate your security token, log in to Salesforce.com and then choose Setup from the user menu. Search for "security token" in the Quick Find box. Click Reset Security Token in the Reset Security Token page. When you receive the token in your email client, copy it and then paste it into the Token field.

  4. Use the Test button to verify that you can successfully connect to Salesforce.com.

Microsoft Access

Using the Salesforce ODBC driver to access Salesforce data as linked data:

  1. Open your Microsoft Access database.
  2. Do one of the following:
    • For Microsoft Access 2003 and earlier, on the File Menu, choose Get External Data > Link Tables.

      The Link dialog box is displayed.

    • For Microsoft Access 2007, on the External Data tab, choose More > ODBC Database.

      The Get External Data wizard starts.

    • For Microsoft Access 2010 and later, on the External Data tab, choose ODBC Database.

      The Get External Data wizard starts.

  3. Do one of the following:
    • For Microsoft Access 2003 and earlier, choose ODBC Databases from the Files of type list.
    • For Microsoft Access 2007 and later, choose Link to the data source by creating a linked table, and then choose OK.

    The Select Data Source dialog box is displayed.

  4. Choose your ODBC data source from the Machine Data Source list, and then choose OK.

    The Link Tables dialog box is displayed.

  5. Choose the table that you want to link and then choose OK.
  6. Choose the linked table in Microsoft Access, and then choose RETURN to work with the linked data.

Using the Salesforce ODBC driver to work with Salesforce data by using SOQL in a pass-through query:

  1. Open your Microsoft Access database.
  2. Create a new Query in Design View. Dismiss the Show Table dialog box.
  3. Right-click the Query tab, and choose SQL View.
  4. Choose Pass-Through as the Query type.
  5. Enter your SOQL statement in the Query pane. For example:
    SELECT Account.Name, (SELECT Contact.LastName FROM Account.Contacts)
    FROM Account
  6. Choose the Run Button. Use the Select Data Source dialog box to choose your Salesforce ODBC driver data source.

Microsoft Excel

Using the Salesforce ODBC driver to access Salesforce data by using SOQL in a pass-through query:

  1. Create a new Excel spreadsheet.
  2. Press ALT+F11 to start the Visual Basic Editor.
  3. In the Visual Basic Editor, in the Project Pane, double-click Sheet1 in the list of Objects.
  4. In the Code Window, add the following VBA code:
    Option Explicit
    
    Public Sub SOQLIntoExcel()
    
        Dim con             As New ADODB.Connection
        Dim rs              As New ADODB.Recordset
        Dim lngCounter      As Long
        Const strcQuery     As String = "SELECT Account.Name, " & _
            "(SELECT Contact.LastName FROM Account.Contacts) FROM Account"
    
        ' Replace SalesforceSOQL with the name of your ODBC data source.
         con.Open "SalesforceSOQL"
         rs.Open strcQuery, con
    
         If rs.EOF Then Exit Sub
    
         With rs
            ActiveSheet.Range("A1").Offset(0, 0).Value = .Fields(0).Name
            ActiveSheet.Range("B1").Offset(0, 0).Value = .Fields(1).Name
            lngCounter = 1
            Do Until .EOF
                ActiveSheet.Range("A1").Offset(lngCounter, 0).Value = .Fields(0).Value
                ActiveSheet.Range("B1").Offset(lngCounter, 0).Value = .Fields(1).Value
                .MoveNext
                lngCounter = lngCounter + 1
            Loop
         End With
    
        rs.Close
        con.Close
    
        Set rs = Nothing
        Set con = Nothing
    
    End Sub
  5. On the Run menu, choose Run Sub/UserForm to run the new subroutine.

    If you get the error "User Defined type not defined.", on the Run menu, choose Reset. On the Tools menu, choose References. In the References dialog box, choose Microsoft Active X Data Objects n Library, and then click OK. Run the subroutine again.