ConnectString Property

Microsoft Office Visual Basic

expression.ConnectString

expression    Required. An expression that returns one of the objects in the Applies To list.

Example

This example checks if the connection string contains the characters ODSOOutlook and displays a message accordingly.

Sub VerifyCorrectDataSource()
    Dim appOffice As OfficeDataSourceObject

    Set appOffice = Application.OfficeDataSourceObject
    appOffice.Open bstrConnect:="DRIVER=SQL Server;SERVER=ServerName;" & _
        "UID=user;PWD=;DATABASE=Northwind", bstrTable:="Employees"

    If InStr(appOffice.ConnectString, "ODSOOutlook") > 0 Then
        MsgBox "Your Outlook address book is used as the data source."
    Else
        MsgBox "Your Outlook address book is not used as the data source."
    End If

End Sub