Solved

Microsoft Access Query Wildcard dilemma

Posted on 2013-06-15
5
459 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 167 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 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 333 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 47

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 333 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

Industry Leaders: 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

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…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

734 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