Opening Multiple Instances of a View

You can open multiple instances of a view in separate work areas, just as you can open a table in more than one work area. Unlike tables, views fetch a new data set by default each time you use the view.

To open a view in multiple work areas

  • In the Project Manager, choose the name of the view, and then choose Browse to display the view in a Browse window. Repeat this process to open the view in additional work areas.

    -or-

  • In the Data Session window, choose Open, and then the name of the view. Repeat this process to open the view in additional work areas.

    -or-

  • Access the view programmatically with the USE command.

When you access the view programmatically with the USE command, you can choose to open another instance of a view without requerying the data source. This is particularly useful when you want to open a remote view in multiple work areas without waiting for data to be downloaded from a remote data source.

To use a view again without downloading data

  • Use the NOREQUERY clause with the USE command.

    -or-

  • Use the AGAIN clause with the USE command.

The following code uses the NOREQUERY clause to display the cursor fetched from the first instance of product_remote_view in two Browse windows without requerying the remote data source:

OPEN DATABASE testdata
CREATE SQL VIEW product_remote_view ;
   CONNECTION remote_01 ;
   AS SELECT * FROM products
USE product_remote_view
BROWSE
SELECT 0
USE product_remote_view NOREQUERY
BROWSE

You can specify a session number with the NOREQUERY clause. If you don't specify a session number, Visual FoxPro searches in all sessions. If an opened result set is found for the view, a cursor is opened again on the same result set. If no open result set is found, a new result set is fetched for the view. As is true for tables, if the view is not found, a new view cursor is opened for you.

If you want Visual FoxPro to search only the current session for an opened result set for your view, you can use the AGAIN clause. The following code displays product_remote_view in two Browse windows:

OPEN DATABASE testdata
USE product_remote_view
BROWSE
USE product_remote_view AGAIN in 0
BROWSE

When you use the AGAIN clause, Visual FoxPro looks for an existing view cursor in the current session, and opens an additional alias pointing to this view cursor. Opening another instance of a view with the AGAIN clause is the equivalent of issuing a USE with the NOREQUERY clause with the current session number.

See Also

Limiting the Scope of a View | Displaying the Structure of a View | Creating Queries | Project Manager | Updating Data in a View