If one is missing, use the other
Let's say you have a database that has the company name and a contacts name.
In some cases the CompanyName field is empty. If that happens, you want to continue the alpha sort using the contact's LastName.
To do this, you need to create an extra query field to provide the sort, using the NZ() function to replace the contents of one field for null values in another.
- Select the Queries, and then click "Create query in Design view".
- Choose the table you want to sort, click Add.
- Click Close.
- Drag down all the fields you want to display in your form, including the two separate fields you want to alphabetize.
- Insert a new column on the left side of the QBE grid.
- In the Field cell, enter the expression
- Select Ascending for the Sort option.
When you run the query, if CompanyName is null (empty — no entry), the NZ() function uses the contents in LastName instead.
Here's another way to do it:
See all Topics