Solved

microsoft access custom query criteria

Posted on 2013-01-16
9
530 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

707 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