Problem with Search query (1 Viewer)

Ramshan

Registered User.
Local time
Today, 14:26
Joined
Aug 17, 2011
Messages
48
Hi everyone,

I am running a problem with my search query. The query I have used is,

SELECT Table1.PropertyName, Table1.City, Table1.Address,Table1.County,Table1.Material
FROM Table1
WHERE (Table1.PropertyName Like Nz(Forms!QueryForm1!PropertyName,"") & "*" And Table1.City Like Nz(Forms!QueryForm1!City,"") & "*" And Table1.Address Like Nz(Forms!QueryForm1!Address,"") & "*");

The Table1 has 5 fields and I have used only 3 for search purpose. The query works fine if the 3 fields which I have used for query contains some value in the table. If any of the value is missing in the table, it is not working. How to resolve this. Please help!, Appreciated.

Thanks
 

Alansidman

AWF VIP
Local time
Today, 16:26
Joined
Jul 31, 2008
Messages
1,493
Try it without the NZ function. With the Like and wildcard, I don't think that you need to have the NZ as part of the criteria.

Alan
 

Ramshan

Registered User.
Local time
Today, 14:26
Joined
Aug 17, 2011
Messages
48
Hi Alansidman,

Even after removing Nz function it is not working. I think the Null values in the query form and table is not matching. I dont know how to resolve it. I have attached the sample access file here. Can anyone resolve it?

The datatable Table 1 contains all values filled for first record, one values missing for second record and 2 values missing fir 3rd record,

In the queryform, try searching for "city" = "oklahoma". It won't work because of the Null value issue.

Thanks!
 

Attachments

  • Test.accdb
    832 KB · Views: 96

recyan

Registered User.
Local time
Tomorrow, 02:56
Joined
Dec 30, 2011
Messages
180
Just see if below gives some guidelines :
Code:
SELECT 
    Table1.PropertyName, 
    Table1.City, 
    Table1.Address, 
    Table1.County, 
    Table1.Material
FROM 
    Table1
WHERE 
IIf(Len(Trim(Forms!QueryForm1!PropertyName))>0,((Table1.PropertyName) Like (Forms!QueryForm1!PropertyName & "*")),IIf(IsNull(Table1.PropertyName),"",(Table1.PropertyName))) 
And 
IIf(Len(Trim(Forms!QueryForm1!City))>0,((Table1.City) Like (Forms!QueryForm1!City & "*")),IIf(IsNull(Table1.City),"",(Table1.City))) 
And 
IIf(Len(Trim(Forms!QueryForm1!Address))>0,((Table1.Address) Like (Forms!QueryForm1!Address & "*")),IIf(IsNull(Table1.Address),"",(Table1.Address)));
Thanks
 

vbaInet

AWF VIP
Local time
Today, 22:26
Joined
Jan 22, 2010
Messages
26,374
See attached.
 

Attachments

  • Test-1.accdb
    500 KB · Views: 114

Users who are viewing this thread

Top Bottom