Introduction.
We design tables carefully to organize information properly so that we can retrieve them easily through search, filter, etc. If you look at the Employees table in the Northwind.mdb sample database, you can see that even an employee's name is split into three parts (Title, First Name & Last Name) and stored in three different fields so that we can work with each piece of information separately. The name fields are defined to a specific length taking into consideration the size of the source information.
When it comes to recording employees' qualifications or work experience, we cannot define the field size to a specific length because the length of information may vary from case to case. This is where we think of the Memo field type. A memo field is a free-form text field where you can record descriptive information of various lengths.
When we want to extract information for reports or views we never think of using the Memo field contents because it has information in an unpredictable form and is considered difficult to work with besides displaying/printing its contents.
Even though Memo Field has only limited flexibility in data filter operations, we can filter records based on specific text spread all over different locations in the memo field.
We can try a few examples with Memo Field data from the Employees Table of Northwind.mdb sample database.
Prepare for a Trial Run.
Import the Employees Table from the sample database C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb.
Open the Employees Table in the datasheet view.
Move the horizontal scrollbar at the bottom to the right, so that the Notes Memo Field contents are visible to you.
Point the mouse at the left border of the table at the intersection of the two rows so that the mouse pointer turns into a cross.
Click and drag down to increase the row size bigger so that the Notes field contents can be viewed properly.
Now, if you look at the qualification information of each employee record you can see that most of them have a BA degree but the text "BA" is not positioned at a specific location in the Memo Field. If you want to filter all employee records with a BA degree, how do we do it?
Let us do it directly on the datasheet view first, before we consider writing a Query to filter data based on the text in the Memo Field.
Highlight the letters BA in any one of the records and Right-click on the highlighted text.
A shortcut menu is displayed and the suggested options for filtering data from the Memo Field are Contains "BA" or Does Not Contain "BA".
Click on the Contains "BA" option to filter the records with the text "BA" appearing anywhere within the memo field.
If you want to filter records this way for printing a Report then we must create Queries to filter data based on the text in Memo Field. You can use the Like Operator combined with AND, OR logical operators.
Copy and paste the following SQL Strings into the SQL Editing Window of new Queries and save them with the suggested names:
Query Name: Employee_BAQ
SELECT Employees.LastName, Employees.FirstName, Employees.Notes FROM Employees WHERE (((Employees.Notes) Like "*BA*"));
The output of this Query will include a record of an employee with an MBA Degree too, because of the text 'BA' in MBA. If you want to exclude this record, then modify the criteria with space immediately after the first asterisk like '* BA*'.
Query Name: Employee_BA_BSCQ
SELECT Employees.LastName, Employees.FirstName, Employees.Notes FROM Employees WHERE (((Employees.Notes) Like "* BA*")) OR (((Employees.Notes) Like "*BSC*"));
The above query gives an example of the usage of the logical operator OR to filter data of employees with graduation in BA or BSC.
Query Name: Employee_BA_BSCQ
SELECT Employees.LastName, Employees.FirstName, Employees.Notes FROM Employees WHERE (((Employees.Notes) Like "* BA*" And (Employees.Notes) Like "*psychology*"));
The above example shows the usage of the logical operator AND and filters the records of the employees with graduation in BA in Psychology.