|[ Team LiB ]|
Recipe 18.7 Export Using a Where Clause
There are two different approaches you can take, depending on how you want the output to look. The first approach is to design a query, and export the query to XML, as shown in the Solution in Recipe 18.5. The second is to use the ExportXML method. (You also could use an XSLT transform, but that would be inefficient unless you also need to format the data.)
The 18-07.MDB sample application has a saved query named qryCarsLessThan40. The SQL Select statement looks like this:
SELECT Car.CarID, Car.Make, Car.Model, Car.Price FROM Car WHERE (((Car.Price)<40000));
The 18-07.MDB sample application also has a function named ExportWhere located in basExportXML. Instead of using a query, this code exports the Car table and programmatically applies a WhereCondition of "Price < 40000":
Application.ExportXML _ ObjectType:=acExportTable, _ DataSource:="Car", _ DataTarget:="c:\test\Where.xml", _ WhereCondition:="Price < 40000"
Figure 18-19 shows the output that is generated.
When you create a saved query with a Where clause and export it, each element is named with the query name, qryCarsLessThan40, as shown in Figure 18-18. When you use the ExportXML method and supply the optional WhereCondition argument, then the name of the table, Car, is used. Although you could rename the query to something less cumbersome than qryCarsLessThan40, you cannot name it Car since there already is a table by that name in the database.
Using the WhereCondition parameter rather than relying on a query also provides extra flexibility. You can use code to construct whatever criteria are needed for the WhereCondition at runtime, rather than having to hard-code the criteria into a query.
|[ Team LiB ]|