Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not like statement not working as expected 1

Status
Not open for further replies.

Triacona

Technical User
Jun 11, 2009
462
GB
Dear All,
Thank you for a great forum [bigsmile]

I have a query - EnAllocationOverdue
I have a form - MainScreen

The query runs off the form.

I use the following criteria within the query.

Code:
WHERE (((UNI7LIVE_ENCASE.RECEPD)<=DateAdd("d",102,[UNI7LIVE_ENCASE].[RECEPD])) AND 

((UNI7LIVE_ENCASE.ENSTAT) Not Like "*" & [Forms]![MainScreen].[cmbEnStat] & "*") AND 

((UNI7LIVE_ENCASE.CLOSED) Is Null));

The problem is with the NOT LIKE.

The field in particular here is cmbEnStat if cmbEnStat is blank, no data is returned.

However if cmbEnStat has a value in it for example NOTICE it returns data with NOTICE excluded.

I have no idea why this is not working.

Any help will be greatly appreciated [thumbsup]
Thank you [smile]




Thank you,

Kind regards

Triacona
 
Try add a zero length string to the field to change it from null to a string:

SQL:
WHERE (((UNI7LIVE_ENCASE.RECEPD)<=DateAdd("d",102,[UNI7LIVE_ENCASE].[RECEPD])) AND 
((UNI7LIVE_ENCASE.ENSTAT [b][COLOR=#A40000][highlight #FCE94F]& ""[/highlight][/color][/b]) Not Like "*" & [Forms]![MainScreen].[cmbEnStat] & "*") AND 
((UNI7LIVE_ENCASE.CLOSED) Is Null));

Duane
Hook'D on Access
MS Access MVP
 
Hi Duane,

Thank you very much for your reply [bigsmile]

I tried what you suggested and the result is still no data and now if I insert a value into cmbEnStat there is no data as well, whereas if there was a value in cmbEnStat in the past there was.

Do you have any other thoughts that could help?

Thank you [smile]

Thank you,

Kind regards

Triacona
 
Try add NZ():
SQL:
WHERE (((UNI7LIVE_ENCASE.RECEPD)<=DateAdd("d",102,[UNI7LIVE_ENCASE].[RECEPD])) AND 
((UNI7LIVE_ENCASE.ENSTAT & "") Not Like "*" & Nz([Forms]![MainScreen].[cmbEnStat],"ZZZZZ") & "*") AND 
((UNI7LIVE_ENCASE.CLOSED) Is Null));

Duane
Hook'D on Access
MS Access MVP
 
What about this ?
SQL:
WHERE UNI7LIVE_ENCASE.RECEPD)<=DateAdd("d",102,[UNI7LIVE_ENCASE].[RECEPD])
 AND (UNI7LIVE_ENCASE.ENSTAT Not Like "*" & [Forms]![MainScreen].[cmbEnStat] & "*" OR Trim([Forms]![MainScreen].[cmbEnStat]='')
 AND (UNI7LIVE_ENCASE.CLOSED)Is Null

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Sorry for the typo.
WHERE UNI7LIVE_ENCASE.RECEPD)<=DateAdd("d",102,[UNI7LIVE_ENCASE].[RECEPD])
AND (UNI7LIVE_ENCASE.ENSTAT Not Like "*" & [Forms]![MainScreen].[cmbEnStat] & "*" OR Trim([Forms]![MainScreen].[cmbEnStat])='')
AND (UNI7LIVE_ENCASE.CLOSED)Is Null

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Dear PHV and Duane,

Thank you both for your time and effort, it is much appreciated [2thumbsup]

I have tried both your solutions and it is Duane's that works.
PHV the result from yours is still producing no data.

Thank you again[smile]


Thank you,

Kind regards

Triacona
 
Dear Duane and PHV,

I have also though of using the NOT IN("","") statement to this effect.

Code:
Not In ("*" & [Forms]![MainScreen].[AddSrch] & "*","*" & [forms]![MainScreen].[SrchCrit] & "*")

I have tried inputting NOTICE into AddSrch and PLNREC into SrchCrit, but it does not exclude as expected.

Any thoughts.

Thank you [smile]

Thank you,

Kind regards

Triacona
 
Dear All,

I have tried the following..

Code:
Not In ([Forms]![MainScreen].[AddSrch],[Forms]![MainScreen].[SrchCrit])

This works if there are values within the 2 text boxes - AddSrch and SrchCrit

How do I get it to accept NULL values and therefore give all the data?

I have tried:
Code:
 Not In (Nz([Forms]![MainScreen].[AddSrch],[Forms]![MainScreen].[SrchCrit]))
I have also tried
Code:
Nz(Not In([Forms]![MainScreen].[AddSrch],[Forms]![MainScreen].[SrchCrit]))

Thanks for your help [smile]

Thank you,

Kind regards

Triacona
 
Dear All,

I have also tried:

Code:
Not In (Nz([Forms]![MainScreen].[AddSrch]),Nz([Forms]![MainScreen].[SrchCrit]))

Thanks [smile]

Thank you,

Kind regards

Triacona
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top