Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

microsoft access custom query criteria

Posted on 2013-01-16
9
Medium Priority
?
536 Views
Last Modified: 2013-01-16
I have the following expression in the criteria of my query, but I keep getting a syntax error.  What I am trying to query in the field called Lot is where the first two characters are numbers followed by the last two digits of the current year followed by numbers again.  Could use expert help please.

Like "[0-9][0-9] & Format([IITDate],"yy") & [0-9]*" And Not Like "*ip"
0
Comment
Question by:sxxgupta
[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
  • 5
  • 4
9 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 38782847
Try this:
Like "'[0-9][0-9]" & Format([IITDate],"yy") & "[0-9]*'" And Not Like "'*ip'"

And if your database is Access, not SQL:

Like "'##" & Format([IITDate],"yy") & "#*'" And Not Like "'*ip'"

Open in new window

0
 
LVL 61

Expert Comment

by:mbizup
ID: 38782871
Correction (assuming you're using the query grid, not VBA):

Like "##" & Format([IITDate],"yy") & "#*" And Not Like "*ip"

Open in new window

0
 

Author Comment

by:sxxgupta
ID: 38782878
Neither one returned any records and I know I have records.......This is an access database with linked SQL tables
0
Independent Software Vendors: 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!

 
LVL 61

Expert Comment

by:mbizup
ID: 38782903
With  linked SQL tables, you most likely need the Access syntax.

Try the first criteria for starters:

Like "##" & Format([IITDate],"yy") & "#*" 

Open in new window


That should returen records like (starting with 2 digits, year, one digit and then anything else):
09138iuoeriouwoer9


SQL equivalent, if your database is set up for SQL compatible syntax:

Like "[0-9][0-9]" & Format([IITDate],"yy") & "[0-9]%" 

Open in new window



The wildcards are:

Access: * for any string of characters;  # for a single numeric digit
SQL Server: % for any string of characters;  [0-9] for a single numeric digit
0
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 total points
ID: 38782935
If the first part of the criteria works, try adding the second.  This will exclude any records that end in 'ip':

Access syntax:
Like "##" & Format([IITDate],"yy") & "#*" And Not Like "*ip"

Open in new window


SQL syntax (notice the change to %ip here):

Like "[0-9][0-9]" & Format([IITDate],"yy") & "[0-9]%" And Not Like "%ip"

Open in new window

0
 

Author Comment

by:sxxgupta
ID: 38782936
Like "##" & Format([IITDate],"yy") & "#*"         gives me records.  Now I just need to narrow it down to 2013.

Eg

011301
211315
061320
111313

etc where the 4th and 5th characters are the last two digits of the date field "IITDate"......
0
 

Author Comment

by:sxxgupta
ID: 38782948
yes using ms access query grid
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38782961
What is the data like in the IITDateField?  Is it an actual full date or is it just the year or a text field?

Try this:

Like "##" & Right([IITDate], 2) & "#*"

Open in new window


<<
etc where the 4th and 5th characters are the last two digits of the date field "IITDate"......
>>

Your data is actually showing this in the 3rd and 4th characters.
0
 

Author Comment

by:sxxgupta
ID: 38782974
added a field IITDate with a where clause:

DatePart("yyyy",[IITDate])>=DatePart("yyyy",Date())

and now was able to narrow the records.  Thanks.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
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.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

636 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