OFF2000: How to Test for a Successful PivotTable Connection (222556)



The information in this article applies to:

  • Microsoft Office PivotTable Component 9.0, run time

This article was previously published under Q222556

SUMMARY

There is no built-in method or property for the Microsoft Office PivotTable that tells you whether you have established a successful connection to your data source. This article illustrates one technique to do this.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. The VBScript code in the following sample Web page illustrates how to detect whether you have made a successful connection to a data source. In this example, the PivotTable list control is named "PivotTable1", and the data source is a SQL Server named "SQLDB".

<HTML>
<BODY ONLOAD = "Setup_PT()">
<OBJECT ID="PivotTable1" 
	CLASSID="CLSID:0002E520-0000-0000-C000-000000000046"
	style="HEIGHT: 500px; WIDTH: 500px">
</OBJECT>
<SCRIPT language=VBScript>
   Sub Setup_PT()
      ' Build the connection string.
      constr="PROVIDER=sqloledb;DATA SOURCE=SQLDB;USERID=sa;" & _              
             "PASSWORD=;INITIAL CATALOG=Northwind"

      ' Disable error handling.
      on error resume next
	
      ' Connect the PivotTable to the database.
      PivotTable1.ConnectionString=constr

      ' Bind the PivotTable to a table in the database.
      PivotTable1.DataMember="dbo.orders"
	
      ' If the PivotTable is not connected to any data...
      if PivotTable1.ActiveData is nothing then

         ' ...Display an error message.
         msgbox "Connection failed."

      else

         ' The connection was successful. Set up the PivotTable.
         set view=PivotTable1.ActiveView
         view.rowaxis.insertfieldset view.fieldsets("customerid")
         view.filteraxis.insertfieldset view.fieldsets("employeeid")
         view.dataaxis.insertfieldset view.fieldsets("orderid")
      end if
End Sub

</SCRIPT>

</BODY>
</HTML>
				

Modification Type:MajorLast Reviewed:6/18/2005
Keywords:kbinfo KB222556