Solved

microsoft access custom query criteria

Posted on 2013-01-16
9
485 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
  • 5
  • 4
9 Comments
 
LVL 61

Expert Comment

by:mbizup
Comment Utility
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
Comment Utility
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
Comment Utility
Neither one returned any records and I know I have records.......This is an access database with linked SQL tables
0
 
LVL 61

Expert Comment

by:mbizup
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
yes using ms access query grid
0
 
LVL 61

Expert Comment

by:mbizup
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

744 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now