To provide query mode to users at runtime:
Turn query mode on by coding:
dw_1.Modify("datawindow.querymode=yes")
All data displayed in the DataWindow is blanked out, though it is still in the DataWindow control's Primary buffer, and the user can enter selection criteria where the data had been.
The user specifies selection criteria in the DataWindow, just as you do when using Quick Select to define a DataWindow object's data source.
Criteria entered in one row are joined together with the AND logical operator; criteria in different rows are joined together with the OR logical operator. Valid operators are =, <>, <, >, <=, >=, LIKE, IN, AND, and OR.
For more information about Quick Select, see the User's Guide.
Call AcceptText and Retrieve, then turn off query mode to display the newly retrieved rows:
dw_1.AcceptText()
dw_1.Modify("datawindow.querymode=no")
dw_1.Retrieve()
The DataWindow control adds the newly defined selection criteria to the WHERE clause of the SELECT statement, then retrieves and displays the specified rows.
Revised SELECT statement You can look at the revised SELECT statement that is sent to the DBMS when data is retrieved with criteria. To do so, look at the sqlsyntax argument in the SQLPreview event of the DataWindow control.
Criteria specified by the user are added to the SELECT statement that originally defined the DataWindow object.
For example, suppose the original SELECT statement for the printer table was:
SELECT printer.rep, printer.quarter, printer.product, printer.units
FROM printer
WHERE printer.units < 70
Figure 10-4 displays a DataWindow with user-entered criteria for the Q1 quarter for Stellar printers, and for the Q2 quarter for all printer products.
Figure 10-4: Example of a DataWindow with a new user query
The SELECT statement generated from this user query is:
SELECT printer.rep, printer.quarter, printer.product, printer.units
FROM printer
WHERE printer.units < 70
AND (printer.quarter = 'Q1'
AND printer.product = 'Stellar'
OR printer.quarter = 'Q2')
Clearing selection criteria To clear the selection criteria, Use the QueryClear property.
dw_1.Modify("datawindow.queryclear=yes")
Sorting in query mode You can allow users to sort rows in a DataWindow while specifying criteria in query mode using the QuerySort property. The following statement makes the first row in the DataWindow dedicated to sort criteria (just as in Quick Select in the DataWindow wizard).
dw_1.Modify("datawindow.querysort=yes")
By default, query mode uses edit styles and other definitions of the column, such as the number of allowable characters. If you want to override these properties during query mode and provide a standard edit control for the column, use the Criteria.Override_Edit property for each column:
dw_1.Modify("mycolumn.criteria.override_edit=yes")
You can also specify this in the DataWindow painter by checking Override Edit on the General property page for the column. With properties overridden for criteria, users can specify any number of characters in a cell (they are not constrained by the number of characters allowed in the column in the database).
You can force users to specify criteria for a column during query mode by coding the following:
dw_1.Modify("mycolumn.criteria.required=yes")
You can also specify this in the DataWindow painter by checking Equality Required on the General property page for the column. Doing this ensures that the user specifies criteria for the column and that the criteria for the column use the = operator rather than other operators, such as < or >=.