Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 28th, 2005, 02:10 PM
Authorized User
 
Join Date: Jan 2005
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using a textbox as query criteria problem

Hello,
I have a problem, I have a query with a criteria for Field1: [Forms]![fTestForm]![txtNumber]
This basically shows me all records with that txtNumber. My dilema is that this query looks at many textboxes as filters and in this case txtNumber might be left blank. Whenever I leave it blank it does not display any records and it should. Is there a way to show records with empty Field1when txtNumber is not selected but if a number was inputed it would display records for the number.

THanks

Let me know if I am confusing you.

 
Old March 28th, 2005, 04:21 PM
Authorized User
 
Join Date: Jan 2005
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Let me rephrase it:
here is my criteria so far,
IIf(Nz([Forms]![fLAMPREditProd]![txtInt2ID],0)=0,Null,[Forms]![fLAMPREditProd]![txtInt2ID])

The False part of it works but whenever the txtInt2ID textbox is empty then the True part does not display Null records. It does not let me put "Is Null" because its a Number field, any idea on the error or a solution to it?
Thanks

 
Old March 28th, 2005, 05:03 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Actually, your query is working correctly... as Access understands it. If there is nothing there in the search textbox, then it is Null. The number of records where the field corresponding to that textbox is null is equal to zero. If you always fill this field with a number, then getting no records back IS CORRECT!

But you want, instead, for Access to show ALL records if your search textbox is null, no? Then change NULL to Not Null (no quotes). Your criteria would look like this:

= Nz([Forms]![fLAMPREditProd]![txtInt2ID],Not Null)

If txtInt2ID has a value, the query looks up the value. If txtInt2ID is null (no value), the Access will return all records where that field is not null.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old March 30th, 2005, 10:04 AM
Authorized User
 
Join Date: Jan 2005
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default

not sure why but its not working

 
Old March 30th, 2005, 11:53 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Greg,

The part of NZ() (above) returned when the first argument is [u]not</u> Null
Code:
[Forms]![fLAMPREditProd]![txtInt2ID]
will return a string, right?
So shouldn’t the part returned if the first argument [u]is</u> Null be a string also ("Not Null")?
 
Old March 30th, 2005, 12:01 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Quote:
quote:Originally posted by BrianWren
The part of NZ() (above) returned when the first argument is [u]not</u> Null
Code:
[Forms]![fLAMPREditProd]![txtInt2ID]
will return a string, right?
That is correct.
Quote:
quote:So shouldn’t the part returned if the first argument [u]is</u> Null be a string also ("Not Null")?
No, that is not correct. If you encase the words with the quotation marks you turn the condition of NOT NULL into a string of "Not Null". You're not looking for a string, you're looking for the condition of the the field having a value. Think of it this way.

5 is a byte, value 5
"5" is a one-character string, value to "5"

True is a boolean, value TRUE or -1.
"True" is a four-character string, value "True"

Null is a reserved Access variable/function denoting no value, value... nothing at all!
"Null" is a four-character string, value "Null"

Not Null is a combination of two reserved words. The Not negates the second part of the condition. Therefore Not Null means to have a value (you don't care what).
"Not Null" is an eight-character string, value "Not Null".

See what I mean? If you put the quotes, your query will actually look for the string "Not Null" in your field rather than search for any value that is not null.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ajax change textbox bgcolor after Criteria met mkthompson Ajax 1 July 28th, 2008 08:56 AM
Conditional criteria in query dfuas Access 1 January 21st, 2006 03:39 AM
Query: getting criteria from a textbox in a form lguzman Access VBA 2 November 1st, 2004 10:16 AM
Criteria in Query lryckman Access 1 June 23rd, 2004 11:11 AM
Query Criteria Clive Astley Access 4 March 25th, 2004 03:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.