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
Solved

microsoft access custom query criteria

Posted on 2013-01-16
9
510 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
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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…

839 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