473,394 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How do I deselect null values from a list box?

Midzie
25
Hi all, I have here a list box bound to my table Closed.Machine, but there are some null values from my table. So my list box have these values: ALL, ,01,02,03, and when I chose "null" the value next to it will appear in my report. Is there a way to exclude null values in my list box? If none, is there a way too that those records with null value from my closed.machine will appear in my query? Here's my code from my list box Row Source property:
Expand|Select|Wrap|Line Numbers
  1. select "All", '1' as lngsort from Closed union select distinct [Closed].[Machine], "2" as lngsort from Closed where ([Closed].[Machine] is not null) order by lngsort
Thanks in advance.
Feb 23 '12 #1

✓ answered by TheSmileyCoder

You could prevent them from occuring in your listbox by modifying the query:
Expand|Select|Wrap|Line Numbers
  1. select "All", '1' as lngsort from Closed union select distinct [Closed].[Machine], "2" as lngsort from Closed where ([Closed].[Machine] is not null and [Closed].[Machine]<>"") order by lngsort 
  2.  
You still need to wonder why you even have empty strings in your database. The default behavior for a textbox when you delete all text in it, is to return to null, not to leave it as a empty string. You can through code force empty strings to be stored as opposed to the default behavior.

You can also for a text field specify that it is not allowed to accept a zero length string (You do this in table design view). For most applications I see only bad coming from allowing zero-length strings, but it is ultimately your call, as I dont know what your requirements are.

5 1980
TheSmileyCoder
2,322 Expert Mod 2GB
It seems there are some inconsistensies in your describtion. As far as I can see your query should not return nulls. I also think you need to find out why you even have nulls in your data (assuming its your data, generated internally, and not coming from an outside source). Nulls often (but not always) indicate you have some failed logic somewhere.


So why do you have null values? Are you even sure its a genuine null and not an empty string? Since if your seing it in your listbox, I am guessing it might be that you have managed to place an empty string in the field.
Feb 23 '12 #2
Midzie
25
I double check the existing table and I found that those are empty values not null values. How do I handle empty values in lstbox?
Feb 23 '12 #3
TheSmileyCoder
2,322 Expert Mod 2GB
You could prevent them from occuring in your listbox by modifying the query:
Expand|Select|Wrap|Line Numbers
  1. select "All", '1' as lngsort from Closed union select distinct [Closed].[Machine], "2" as lngsort from Closed where ([Closed].[Machine] is not null and [Closed].[Machine]<>"") order by lngsort 
  2.  
You still need to wonder why you even have empty strings in your database. The default behavior for a textbox when you delete all text in it, is to return to null, not to leave it as a empty string. You can through code force empty strings to be stored as opposed to the default behavior.

You can also for a text field specify that it is not allowed to accept a zero length string (You do this in table design view). For most applications I see only bad coming from allowing zero-length strings, but it is ultimately your call, as I dont know what your requirements are.
Feb 23 '12 #4
NeoPa
32,556 Expert Mod 16PB
The following SQL should populate your ListBox control appropriately :
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT [Machine]
  2.               , '2' AS [lngSort]
  3. FROM            [Closed]
  4. WHERE           ([Machine] > '')
  5. UNION
  6. SELECT          'All'
  7.               , '1'
  8. ORDER BY        [lngSort]
NB. Smiley's advice should be followed though. It makes sense.
Feb 23 '12 #5
Midzie
25
Hi Smiley/Neopa,

Thanks for the reply, my concern has been resolved. Thank you very much :-)
Feb 27 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Marcus | last post by:
Hello, quick question about MySQL storing NULL values... Say I have a textbox called $_POST and a variable $var. if(empty($_POST)) $var = NULL; else $var = $_POST; Disregarding...
26
by: Agoston Bejo | last post by:
I want to enforce such a constraint on a column that would ensure that the values be all unique, but this wouldn't apply to NULL values. (I.e. there may be more than one NULL value in the column.)...
4
by: Brendan McLoughlin | last post by:
Hi, I am looking for opinions and alternatives for handling null values in a data object which reads a record from a database table. This object will have properties which will be populated...
6
by: Tino Wildenhain | last post by:
Hi, SELECT 'abc'::text || 'def'::text; returns 'abcdef' as we know. SELECT 'abc'::text || ''::text; returns 'abc'
6
by: AAVF | last post by:
Hi We have a problem with a query. An Access database links via ODBC to a UNIX server. To speed things, we use the ODBC to load the relevant tables to the local PC that runs Access so that...
5
by: William Wisnieski | last post by:
Hello Everyone, I have a query by form with several list boxes. The user selects items from the list boxes and clicks a button that returns results in a datasheet subform. One of the list...
3
by: google | last post by:
This is something I've done plenty of times in '97, but I can't seem to get it to work correctly in Access 2003. Say, for example, I have a form with an unbound combobox, the data source is a...
6
by: doncee | last post by:
I have a list box that is generated on a form by way of a Parameter Query. Problem is whenever I try to refer to the list box, i.e., to update the underlying table, I am getting a "null" value...
3
by: tonialbrown | last post by:
I am having some problems with an update statement. The problem is the data comes from a list box lstDelFrom that the user selects for the required record that they are copying the data from. This...
10
by: =?Utf-8?B?R3JlZw==?= | last post by:
I have the following three files. 1. Users.aspx is a webpage that uses the <asp:ObjectDataSourcecontrol to populate a simple <asp:ListBoxcontrol. 2. The UserDetails.cs file creates a Namespace...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.