Solved

Multi field criteria entry form

Posted on 2014-01-23
3
629 Views
Last Modified: 2014-01-29
I have a form which contains 5 unbound fields.

The form is meant to be a form the user can use to select the criteria for a query.

For example, one of the fields is "Bay".  In the query then I have this in the criteria:

Like "*" & [Forms]![frmSelectCriteriaForInventoryExports]![txtBay] & "*"

So the user can enter a value in this field and the query will return the records that have that value for "Bay".

But I also have a two fields for dates.  They are txtStartDate and txtEndDate.

In the query criteria I have:

Like "*" & Between Forms![frmSelectCriteriaForInventoryExports]![txtStartDate] and Forms![frmSelectCriteriaForInventoryExports]![txtEndDate] & "*"

But that doesn't work.

???
0
Comment
Question by:SteveL13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 37

Expert Comment

by:PatHartman
ID: 39805035
It won't work because dates are not stored as strings and LIKE only works with strings.  I also wouldn't use LIKE at all unless I have partial strings since LIKE can prevent the query engine from optimizing the query and force it to read EVERY record, one at a time.  If you have a partial string, you have to take the hit but if you are working with combos - don't use LIKE since you never have a partial string.  Here's what I do with forms like this:

Where (fld1 = Forms!yourform!fld1 OR Forms!yourForm!fld1 Is Null)
AND (fld2 = Forms!yourform!fld2 OR Forms!yourform!fld2 Is Null)
AND (date1 Between Forms!yourForm!fromdate AND Forms!yourform!thrudate OR Forms!yourForm!fromdate Is Null)
AND ...

Notice the parentheses.  They are critical when your expressions are complex and include both AND and OR.  On your form, you can edit the from and thru dates to make sure both exist when one does so the query only needs to check one.

Access is going to destroy all your wonderful formatting (plus add monumental numbers of extraneous parentheses) so it can render the criteria in QBE view.  To prevent that from happening, leave the query in SQL view and make sure you save it that way.  You can switch to QBE view but just remember to not save the query from that view.
0
 

Author Comment

by:SteveL13
ID: 39806600
I appreciate your response.  Thank you.  But somehow I have to be able to create a query using information the user entered into the form.

I've attached a screen shot of the form.  If the user leaves every field blank then they get all records.  If they enter, for example "83" in the Bay field then they get the records that have 83 in the bay field in the table.

If the enter a category then they get all records in that category.

If they enter a category and a start date and an end date, they get all records with that category and a Date between the start date and end date.

Isn't there a way I can do this?

--Steve
Selection-Form.jpg
0
 
LVL 37

Accepted Solution

by:
PatHartman earned 500 total points
ID: 39806718
The example I showed you does that.  It is EXACTLY what you need.  Just substitute your own column names.

The "fld1 = Forms!yourform!fld1" part of the expression selects records that match the value from the form.  The "OR Forms!yourform!fld1" part of the expression checks the form field for null and if it is null, the expression returns true which will select ALL values.

The "AND" operators that connect the expressions combine them so that if you enter something in more than one field, they all must be true.

By combining the (xx OR yy) AND (aa OR bb) AND (cc OR dd) sets in the query, your SQL is static and you don't need to build it on the fly.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question