You are here:

Using MS Access/Access 2007 query only displays old values, not new entries.

Advertisement


Question
QUESTION: Hi,

I've created a database to manage our company's library. One form is meant for input into a single table: "Inventory".

A search form has been created to look up publications. On this form, there's a search button. When clicked, this opens a form ("Search_form_results") based on a query. The SQL for this query is as follows:

SELECT Inventory.Bibliographic_reference, Inventory.Period, Inventory.Material_category, Inventory.Region, *
FROM Inventory
WHERE (((Inventory.Bibliographic_reference) Like "*" & forms!Searchform!Choose_author & "*"
And (Inventory.Bibliographic_reference) Like "*" & forms!Searchform!Choose_title
And (Inventory.Bibliographic_reference) Like "*" & forms!Searchform!Choose_title & "*"
And (Inventory.Bibliographic_reference) Like "*" & forms!Searchform!Choose_series
And (Inventory.Bibliographic_reference) Like "*" & forms!Searchform!Searchterm & "*"
And (Inventory.Bibliographic_reference) Like "*" & forms!Searchform!Choose_author & "*"
And (Inventory.Bibliographic_reference) Like "*" & forms!Searchform!Choose_title
And (Inventory.Bibliographic_reference) Like "*" & forms!Searchform!Choose_title & "*"
And (Inventory.Bibliographic_reference) Like "*" & forms!Searchform!Choose_series
And (Inventory.Bibliographic_reference) Like "*" & forms!Searchform!Searchterm & "*")
And ((Inventory.Period) Like "*" & forms!Searchform!Choose_period & "*")
And ((Inventory.Material_category) Like "*" & forms!Searchform!Choose_material & "*")
And ((Inventory.Region) Like "*" & forms!Searchform!Choose_region & "*"))
ORDER BY Inventory.Bibliographic_reference;

This worked perfectly for the existing records in the "Inventory" table. However, I have recently added some new records to this table. When I now run the query, it only displays the old values and ignores the newer entries in the table.

How can I include these new entries as well?

Thanks!

ANSWER: I suspect the newer records are missing some value in one of the fields. Using the LIKE operator with wildcards like you are doing will ignore Nulls. So if you have even one of the search fields having a null value, it won't be returned.

Hope this helps,
Scott<>
Blog: http://scottgem.wordpress.com
Website: http://www.diamondassoc.com
Microsoft Access MVP 2007
Author: Microsoft Office Access 2007 VBA

---------- FOLLOW-UP ----------

QUESTION: Thank you for your quick response.

How can I overcome this? Do I have to enter "Is Null" somewhere?

Thanks.

Answer
So that was the problem? If so, then you are going to have Add an OR conditions within each check for Is Null. Something like this:

WHERE (Inventory.Bibliographic_reference) Like "*" & forms!Searchform!Choose_author & "*"
And (Inventory.Bibliographic_reference Like "*" & forms!Searchform!Choose_title
And (Inventory.Bibliographic_reference) Like "*" & forms!Searchform!Choose_title & "*"
And (Inventory.Bibliographic_reference) Like "*" & forms!Searchform!Choose_series
And (Inventory.Bibliographic_reference) Like "*" & forms!Searchform!Searchterm & "*"
And (Inventory.Bibliographic_reference) Like "*" & forms!Searchform!Choose_author & "*"
And (Inventory.Bibliographic_reference) Like "*" & forms!Searchform!Choose_title
And (Inventory.Bibliographic_reference) Like "*" & forms!Searchform!Choose_title & "*"
And (Inventory.Bibliographic_reference) Like "*" & forms!Searchform!Choose_series
And (Inventory.Bibliographic_reference) Like "*" & forms!Searchform!Searchterm & "*" OR Inventory.Bibliographic_reference Is Null)
And ((Inventory.Period) Like "*" & forms!Searchform!Choose_period & "*")
And ((Inventory.Material_category) Like "*" & forms!Searchform!Choose_material & "*")
And ((Inventory.Region) Like "*" & forms!Searchform!Choose_region & "*"))

Or you can not allow Nulls and set the default value of each field to a zero length string (""). If you choose the latter, you can run an Update query that updates all Nulls to a zero length string.

Hope this helps,
Scott<>
Blog: http://scottgem.wordpress.com
Website: http://www.diamondassoc.com
Microsoft Access MVP 2007
Author: Microsoft Office Access 2007 VBA

Using MS Access

All Answers


Answers by Expert:


Ask Experts

Volunteer


Scottgem

Expertise

I can answer almost all types of questions relating to Microsoft Access usage and application design. My strengths are database and interface design.

Experience

I've been designing databases for over 25 years working with dBase, FoxPro, Approach and Access.

Organizations
Author of Microsoft Office Access 2007 VBA
Techncial Editor for Special Edition Using Microsoft Access 2007 and Access 2007 Forms, Reports & Queries From Que Publishing

Education/Credentials
Brooklyn College BA

©2016 About.com. All rights reserved.