Solved

microsoft access custom query criteria

Posted on 2013-01-16
9
519 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
Technology Partners: 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 500 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

726 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