Source Property Example

This example demonstrates the Source property by opening three Recordset objects based on different data sources.

Public Sub SourceX()

	Dim cnn1 As ADODB.Connection
	Dim rstTitles As ADODB.Recordset
	Dim rstPublishers As ADODB.Recordset
	Dim rstTitlesPublishers As ADODB.Recordset
	Dim cmdSQL As ADODB.Command
	Dim strCnn As String
	Dim strSQL As String

	' Open a connection.
	Set cnn1 = New ADODB.Connection
	strCnn = "driver={SQL Server};server=srv;" & _
		"uid=sa;pwd=;database=pubs"
	cnn1.Open strCnn
	
	' Open a recordset based on a command object.
	Set cmdSQL = New ADODB.Command
	Set cmdSQL.ActiveConnection = cnn1
	cmdSQL.CommandText = "Select title, type, pubdate " & _
		"FROM titles ORDER BY title"
	Set rstTitles = cmdSQL.Execute()
	
	' Open a recordset based on a table.
	Set rstPublishers = New ADODB.Recordset
	rstPublishers.Open "publishers", strCnn, , , adCmdTable
	
	' Open a recordset based on an SQL string.
	Set rstTitlesPublishers = New ADODB.Recordset
	strSQL = "SELECT title_ID AS TitleID, title AS Title, " & _
		"publishers.pub_id AS PubID, pub_name AS PubName " & _
		"FROM publishers INNER JOIN titles " & _
		"ON publishers.pub_id = titles.pub_id " & _
		"ORDER BY Title"
	rstTitlesPublishers.Open strSQL, strCnn, , , adCmdText

	' Use the Source property to display the source of each recordset.
	MsgBox "rstTitles source: " & vbCr & _
		rstTitles.Source & vbCr & vbCr & _
		"rstPublishers source: " & vbCr & _
		rstPublishers.Source & vbCr & vbCr & _
		"rstTitlesPublishers source: " & vbCr & _
		rstTitlesPublishers.Source

	rstTitles.Close
	rstPublishers.Close
	rstTitlesPublishers.Close
	cnn1.Close

End Sub

© 1997 Microsoft Corporation. All rights reserved.