(c) 2002 Visual Studio Magazine 
Fawcette Technical Publications

Issue: April 2002
Section: Database Design
Author: Andy Clark

VB6, SQL Server 7+, ADO 2.0+, MSDataShape Provider		Use a Simple Shape Command
Listing 1	This code shows a subroutine that runs a SHAPE command on the Northwind database. SimpleShape executes the SHAPE command using the rs.Open method and works through the two recordsets created by the command.

Private Sub SimpleShape(pConn As _
	ADODB.Connection)
Dim rs As New ADODB.Recordset
Dim rsOrd As New ADODB.Recordset

rs.Open "SHAPE {SELECT CustomerID,CompanyName" _
	& " FROM Customers ORDER BY CompanyName}" _
	& " APPEND ({SELECT OrderId, OrderDate," _
	& "CustomerID FROM Orders} AS rsOrd" _
	& " RELATE CustomerID to CustomerID)",_
	pConn, adOpenKeyset, adLockOptimistic

With rs
	Set rsOrd = .Fields("rsOrd").Value
	Do While Not .EOF
			Debug.Print "Orders for CustomerId " _
				& !CustomerID & " company " & _
				!CompanyName
		Do While Not rsOrd.EOF
			Debug.Print " " & rsOrd!OrderId _
				& " on " & rsOrd!OrderDate
			rsOrd.MoveNext
		Loop
		.MoveNext
	Loop
	rsOrd.Close
	.Close
End With

Set rsOrd = Nothing
Set rs = Nothing

End Sub
