You can open a view in separate work areas similar to how you can open a table in different work areas. For more information, see How to: Open Tables in Work Areas.
However, unlike tables, views retrieve a new data set each time you use the view. When you open the view programmatically with the USE command, you can open additional instances of the view without retrieving data from the data source. This is particularly useful when you want to open a remote view in multiple work areas without waiting to download data from remote data sources.
To open another instance of a view without downloading data
Open the view with the USE command and include the NOREQUERY or AGAIN clause.
You can specify a data session number when using the NOREQUERY clause. If you omit a data session number, Visual FoxPro searches in all data sessions. If an opened result set is found for the view, Visual FoxPro opens the cursor again on the same result set. If no open result set is found, Visual FoxPro retrieves a new result set for the view. As is true with tables, if the view is not found, Visual FoxPro opens a new cursor for the view.
If you want Visual FoxPro to search only the current data session for an opened result set, use the AGAIN clause. Opening another instance of a view with the AGAIN clause is the equivalent using the NOREQUERY clause with the current session number.
For more information, see USE Command.
For example, the following code opens the sample Northwind database using the OPEN DATABASE command, creates a remote view named Product_View using the CREATE SQL VIEW command and selects all the records in the Products table. The USE command opens the view, and the BROWSE command displays the first instance of the view in a browse window. The SELECT command selects the work area of the view, and the USE command opens the same view with the NOREQUERY clause. This time, the BROWSE command displays the view in a browse window without retrieving the data from the data source:
OPEN DATABASE HOME(2) + "Northwind\Northwind" CREATE SQL VIEW Product_View AS SELECT * FROM Products USE Product_View BROWSE SELECT 0 USE Product_View NOREQUERY BROWSE
The following code uses the USE command to open the view and the BROWSE command to display the view in a browse window. The second USE command opens the view from the current data session with the AGAIN clause using a different alias. The BROWSE command displays the view with the different alias:
OPEN DATABASE HOME(2) + "Northwind\Northwind" USE Product_View BROWSE USE Product_View AGAIN IN 0 BROWSE
The following command deletes the view when you are finished working with it:
DELETE VIEW Product_View