DataSource Property

Microsoft Office Visual Basic

expression.DataSource

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

Example

The following example sets the name of the data source if the name is blank.

Sub SetAndReturnDataSourceName()
    Dim appOffice As OfficeDataSourceObject

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

        If .DataSource = "" Then
            .DataSource = "Northwind"
            MsgBox .DataSource
        End If
    End With
End Sub