?
Solved

Microsoft Access Query Wildcard dilemma

Posted on 2013-06-15
5
Medium Priority
?
461 Views
Last Modified: 2013-06-17
OK I'm going crazy... I've tried the * and the % to no avail.

Here is the SQL code of the query:

SELECT tempDocList.FName, tempDocList.FPath, [forms]![frmEquipment]![PartNo] AS PN, [forms]![frmEquipment]![SerialNo] AS SN, [forms]![frmEquipment]![ModelNo] AS MN, [forms]![frmEquipment]![EquipmentDesc] AS [Desc], [forms]![frmEquipment]![FirmWare] AS FW
FROM tempDocList
WHERE (((tempDocList.FName) Like "%" & [forms]![frmEquipment]![PartNo] & "%*") AND (([forms]![frmEquipment]![PartNo])<>"" And ([forms]![frmEquipment]![PartNo]) Is Not Null)) OR (((tempDocList.FPath) Like "%" & [forms]![frmEquipment]![PartNo] & "%") AND (([forms]![frmEquipment]![PartNo])<>"" And ([forms]![frmEquipment]![PartNo]) Is Not Null)) OR (((tempDocList.FName) Like "%" & [forms]![frmEquipment]![SerialNo] & "%") AND (([forms]![frmEquipment]![SerialNo])<>"" And ([forms]![frmEquipment]![SerialNo]) Is Not Null)) OR (((tempDocList.FPath) Like "%" & [forms]![frmEquipment]![SerialNo] & "%") AND (([forms]![frmEquipment]![SerialNo])<>"" And ([forms]![frmEquipment]![SerialNo]) Is Not Null)) OR (((tempDocList.FName) Like "%" & [forms]![frmEquipment]![ModelNo] & "%") AND (([forms]![frmEquipment]![ModelNo])<>"" And ([forms]![frmEquipment]![ModelNo]) Is Not Null)) OR (((tempDocList.FPath) Like "%" & [forms]![frmEquipment]![ModelNo] & "%") AND (([forms]![frmEquipment]![ModelNo])<>"" And ([forms]![frmEquipment]![ModelNo]) Is Not Null)) OR (((tempDocList.FName) Like "%" & [forms]![frmEquipment]![FirmWare] & "%") AND (([forms]![frmEquipment]![FirmWare])<>"" And ([forms]![frmEquipment]![FirmWare]) Is Not Null)) OR (((tempDocList.FPath) Like "%" & [forms]![frmEquipment]![FirmWare] & "%") AND (([forms]![frmEquipment]![FirmWare])<>"" And ([forms]![frmEquipment]![FirmWare]) Is Not Null)) OR (((tempDocList.FName) Like "%" & [forms]![frmEquipment]![EquipmentDesc] & "%") AND (([forms]![frmEquipment]![EquipmentDesc])<>"" And ([forms]![frmEquipment]![EquipmentDesc]) Is Not Null)) OR (((tempDocList.FPath) Like "%" & [forms]![frmEquipment]![EquipmentDesc] & "%") AND (([forms]![frmEquipment]![EquipmentDesc])<>"" And ([forms]![frmEquipment]![EquipmentDesc]) Is Not Null));

I'm attaching a spreadsheet with the data for the table "tempDocList" -- if you can create a query with the above string and create a table named as the spreadsheet and tell me what I'm doing wrong??
tempDocList.xlsx
0
Comment
Question by:Ei0914
[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 Comments
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 39250890
Hi,
what is your data source? Tables in Access or SQL server?
Where is your query executed?
Can you post the code where you build the query string?
Thanks.
Rainer
0
 
LVL 34

Assisted Solution

by:Norie
Norie earned 668 total points
ID: 39250916
What is your query meant to return?

In Access % isn't a wildcard, the usual wildcard is *.

So something like this,

tempDocList.FName Like "%" & [forms]![frmEquipment]![PartNo] & "%*")

Should look like this.

tempDocList.FName Like "*" & [forms]![frmEquipment]![PartNo] & "*"
 
Does the query work without the criteria?

If it does try adding the criteria back in a section at a time and test as you go.
0
 
LVL 48

Accepted Solution

by:
Dale Fye earned 1332 total points
ID: 39251197
A couple of issues.

1.  As mentioned above, the wildcard you are seeking in Access is the *, not the %.  If you are using SQL Server as you back-end, and the query is being executed on the SQL Server via a Pass-Thru query, you would use the %.

2.  Since 'FName' and [FPath] are strings, you have to wrap the search strings 'PartNo', 'SerialNo' in quotes.  I've uses single quotes in my example below.  Note that there is a '* before each of the form fields and a *' after each.  Assuming that your [PartNo] field on your form contains "abcd", they syntax would return something like the following:

[FName] LIKE '*abcd*'

3.  There is an easier way to test for an empty string or a NULL value.  There are actually several, you could use:

 [forms]![frmEquipment]![PartNo] & "" <> ""

or you could use

NZ( [forms]![frmEquipment]![PartNo], "") <> ""

Either of these will significantly increase the readability of your query.

So, you might try:
WHERE (tempDocList.FName Like "'*" & [forms]![frmEquipment]![PartNo] & "*'" AND
       NZ([forms]![frmEquipment]![PartNo], "") <> "")
OR (tempDocList.FPath Like "'*" & [forms]![frmEquipment]![PartNo] & "*'" AND 
       NZ([forms]![frmEquipment]![PartNo], "") <> "")
OR (tempDocList.FName Like "'*" & [forms]![frmEquipment]![SerialNo] & "*'" AND
        NZ([forms]![frmEquipment]![SerialNo], "") <> "")
OR (tempDocList.FPath Like "'*" & [forms]![frmEquipment]![SerialNo] & "*'" AND
        NZ([forms]![frmEquipment]![SerialNo], "") <> "")
OR (tempDocList.FName Like "'*" & [forms]![frmEquipment]![ModelNo] & "*'" AND
       NZ([forms]![frmEquipment]![ModelNo], "") <> "") 
OR (tempDocList.FPath Like "'*" & [forms]![frmEquipment]![ModelNo] & "*'" AND
       NZ([forms]![frmEquipment]![ModelNo], "") <> "") 
OR (tempDocList.FName Like "'*" & [forms]![frmEquipment]![FirmWare] & "*'" AND
       NZ([forms]![frmEquipment]![FirmWare], "") <> "") 
OR (tempDocList.FPath Like "'*" & [forms]![frmEquipment]![FirmWare] & "*'" AND
       NZ([forms]![frmEquipment]![FirmWare], "") <> "") 
OR (tempDocList.FName Like "'*" & [forms]![frmEquipment]![EquipmentDesc] & "*'" AND
       NZ([forms]![frmEquipment]![EquipmentDesc], "") <> "") 
OR (tempDocList.FPath Like "'*" & [forms]![frmEquipment]![EquipmentDesc] & "*'"  AND
       NZ([forms]![frmEquipment]![EquipmentDesc], "") <> "");

Open in new window

0
 
LVL 48

Assisted Solution

by:Dale Fye
Dale Fye earned 1332 total points
ID: 39251202
Since you are comparing two text fields to several other values, you could also concatenate those fields together, something like:
WHERE (tempDocList.FName & "!" & tempDocList.FPath Like "'*" & [forms]![frmEquipment]![PartNo] & "*'" AND
       NZ([forms]![frmEquipment]![PartNo], "") <> "")
OR (tempDocList.FName & "!" & tempDocList.FPath Like "'*" & [forms]![frmEquipment]![SerialNo] & "*'" AND
       NZ([forms]![frmEquipment]![SerialNo], "") <> "")
OR (tempDocList.FName & "!" & tempDocList.FPath Like "'*" & [forms]![frmEquipment]![ModelNo] & "*'" AND
       NZ([forms]![frmEquipment]![ModelNo], "") <> "")
OR (tempDocList.FName & "!" & tempDocList.FPath Like "'*" & [forms]![frmEquipment]![FirmWare] & "*'" AND
       NZ([forms]![frmEquipment]![FirmWare], "") <> "")
OR (tempDocList.FName & "!" & tempDocList.FPath Like "'*" & [forms]![frmEquipment]![EquipmentDesc] & "*'" AND
       NZ([forms]![frmEquipment]![EquipmentDesc], "") <> "")

Open in new window

In my example above, I have concatenated the two text field together into a single string, using an exclamation point as a field seperator.  Depending on what your various search fields (PartNo, SerialNo, ModelNo, ...) look like, you might want to make the !! or ZZ or some other combination.
0
 

Author Closing Comment

by:Ei0914
ID: 39254990
I broke the query into multiple queries which seems to be less complicated and is returning the records I wanted. Thanks for all your help!
0

Featured Post

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!

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
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.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

762 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