A family of Microsoft relational database management systems designed for ease of use.
If the Like actually had something in it to match, that string would still select everything that was null as well.
That's not so. If the above is entered in the 'criteria' row of a query in design view, which is what Wayne was suggesting, the equivalent SQL would be along these lines:
SELECT DISTINCT CompanyName, <more columns>
FROM Companies INNER JOIN CompanyKeyWords
ON Companies.CompanyID = CompanyKeyWords.CompanyID
WHERE (CompanyName LIKE "*" & Forms!FormName!txtCompany & "*"
OR Forms!FormName!txtCompany IS NULL)
AND (Town LIKE "*" & Forms!FormName!txtTown & "*"
OR Forms!FormName!txtTown IS NULL)
AND (KeyWord LIKE "*" & Forms!FormName!txtKeyWord & "*"
OR Forms!FormName!txtKeyWord IS NULL)
< and so on>;
Each parenthesised OR operation evaluates independently of the AND operations. Taking Town as an example, if there is a value at the Town column position in a row and a value has been entered into the txtTown control the parenthesised expression will evaluate to TRUE if the value matches the pattern as the first part of the OR operation will evaluate to TRUE and restrict the rows returned to the matching rows. If on the other hand there is no value entered into the control, i.e. it is NULL then the second part of the OR operation will evaluate to TRUE for all rows regardless of the value in the Town column, or if there column is NULL, so all rows not restricted by the other criteria will be returned..
This is the normal way of 'optionalising' parameters in a query and should be adopted if you are using a saved query. If on the other hand you are building the SQL statement in code do as Doug advises and simply exclude the criterion from the WHERE clause.
If you do write and save a query in this way, however, do so in SQL view. Do not do so in design view or switch from SQL view to design view before saving the query as Access will move things around and the underlying logic, while fundamentally the same, will be obscured and difficult to amend.