Solved

Access 2003 - Query Criteria

Posted on 2011-04-20
Medium Priority
163 Views
I have a query with a mix of blanks; 4 digit codes and 8 digit codes under my Pr/Br field with the 4 digits being the pr's and the 8 digits being the Brs.  I only want the blanks and Pr which have 4 digit codes to appear in my query.  What could I type in the criteria under Pr/Br to only get the blanks and the pr's 4 digits to appear?

Thank you.
0
Question by:karenlancaster
• 3
• 3

LVL 46

Expert Comment

ID: 35439548
I don't think you can do it in the query wizard criteria box.  However, if you switch your view to SQL, you can add this condition to the Select statement:
``````WHERE Len(Trim([Pr/Br]))=0 or [Pr/Br] Like "####"
``````
0

LVL 40

Expert Comment

ID: 35439680
If you have only 4 or 8 digits in your Pr/Br field, you can check length of string:
len([Pr/Br]) and criteria will be 4
If you can have characters, use criteria:
like "*####*"
0

LVL 46

Expert Comment

ID: 35439716
@als315

Your pattern would be more efficient if you dropped the leading and trailing wildcards: like "####"  rather than like "*####*"

>>What could I type in the criteria under Pr/Br
Given this problem criterion, you should probably explicitly state that the length check part of your solution is not located under [Pr/Br].
0

LVL 40

Expert Comment

ID: 35441193
@aikimark:
I've added wildcards for possible case:
abc1234def
Cases 1234 and 56789012 can be selected by len().
There is one else possible case - field is numeric:
criteria will be < 10000
Until we have no examples we can only suppose something
0

LVL 46

Expert Comment

ID: 35441283
@als315

Since the question specified "digits" or "spaces", I don't think we would encounter "abc1234def".

I've a hunch that this field would be better as a nullable long integer field, both from a performance and data entry (validation) perspective.
0

LVL 40

Assisted Solution

als315 earned 1000 total points
ID: 35442952
@aikimark
I also think so and you also are right with wildcards. Correct criteria for this (not too likely) case will be:
like "*####*" and not like "*#####*"
0

LVL 44

Accepted Solution

GRayL earned 1000 total points
ID: 35442964
Another way to skin the cat:

WHERE Nz([Pr/Br],"0000") like "####"
0

Featured Post

Question has a verified solution.

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

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month14 days, 1 hour left to enroll