04 CopyWhere - AndrewMB2/Logic-Architect-for-Excel-VBA GitHub Wiki
Copies data from another Xd object where defined criteria are true. Returns True if successful, otherwise False.
Applies to
| TableData | ArrData | RsetData | Xdata | XShared |
|---|---|---|---|---|
| ✓ |
Parameters
| Name | Type | Description |
|---|---|---|
| Xd | Xdata object | Object from which data should be copied. |
| Criteria | Variant | Array of criteria or name of user defined function. |
| Fields | Value, array or ParamArray | Fields to be copied. |
CopyWhere copies data from Xd and appends the data to whatever may already be in the calling ArrData object, where the criteria conditions are satisfied. Fields is the list of fields to be copied. If no list of fields is supplied then all fields are copied which are present on both objects. If Fields is * then all fields from Xd are copied and must be present on the calling ArrData object.
Criteria is an array of the fields and comparison values to be used (field name and value form adjacent parameters). The value can be preceded by any of =, <, <=, >, >=, <> for different types of comparison. If the value is an array, the field is tested to be any of the values in the array. If the value is Empty, the comparison for this field is ignored.
Where criteria are specified for more than one field, then all the criteria must be met for a record to be kept (AND filter). However it is possible to use Not as the first parameter which reverses the entire comparison set, and this can be used to set up an OR filter (e.g. Not, "Field1", "<>2", "Field2", "<>2" will allow through records where Field1 = 2 or Field2 = 2).
All the comparison fields must be on the Arrdata object.
CopyWhere also supports filtering with a user defined function. The name of the user defined function is supplied as the single criteria parameter. For more information on writing user defined functions see Transforming Data.