Solved

Microsoft Access Query Wildcard dilemma

Posted on 2013-06-15
5
455 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
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 33

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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 …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

911 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

18 Experts available now in Live!

Get 1:1 Help Now