473,398 Members | 2,525 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,398 software developers and data experts.

Null Values as Option in List Box

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 boxes [lstStatus] contains two values: Call Back and No
Answer. The user can select either one or both and the proper results are
returned. If the user doesn't use this list box, then all Call Backs, No
Answers, and Null values are returned. As another option, I would like the
user to be able to select ONLY those records where the value of the field is
Null.

What code could I add to do that? Here is what I have that works as stated
above:

If Me!lstStatus.ItemsSelected.Count > 0 Then
If Len(strWhere) > 0 Then
strWhere = strWhere & "AND" & "[Status] IN ("
For i = 0 To lstStatus.ListCount - 1
If lstStatus.Selected(i) Then
strWhere = strWhere & "'" & lstStatus.Column(0, i) & "', "
End If
Next i
strWhere = Left(strWhere, Len(strWhere) - 2) & ")"
Else
strWhere = strWhere & "[Status] IN ("
For i = 0 To lstStatus.ListCount - 1
If lstStatus.Selected(i) Then
strWhere = strWhere & "'" & lstStatus.Column(0, i) & "', "
End If
Next i
strWhere = Left(strWhere, Len(strWhere) - 2) & ")"
End If
End If

Thanks for your help!

William
Nov 12 '05 #1
5 4109
For this scenario, I thin an option group with four radio buttons
would be simpler: Call Back, No Answer, Both, and None. You could
then create your Where clauses easily based on the option selected:

Call Back
Status = "Call Back"

No Answer
Status = "No Answer"

Both
Status IN ("Call Back", "No Answer")

None
Status IS NULL

From a UI perspective, I think that is also simpler than a multiselect
listbox. HTH

Rick Collard
www.msc-lims.com

On Thu, 26 Feb 2004 11:33:47 -0500, "William Wisnieski"
<ww********@admissions.umass.edu> wrote:
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 boxes [lstStatus] contains two values: Call Back and No
Answer. The user can select either one or both and the proper results are
returned. If the user doesn't use this list box, then all Call Backs, No
Answers, and Null values are returned. As another option, I would like the
user to be able to select ONLY those records where the value of the field is
Null.

What code could I add to do that? Here is what I have that works as stated
above:

If Me!lstStatus.ItemsSelected.Count > 0 Then
If Len(strWhere) > 0 Then
strWhere = strWhere & "AND" & "[Status] IN ("
For i = 0 To lstStatus.ListCount - 1
If lstStatus.Selected(i) Then
strWhere = strWhere & "'" & lstStatus.Column(0, i) & "', "
End If
Next i
strWhere = Left(strWhere, Len(strWhere) - 2) & ")"
Else
strWhere = strWhere & "[Status] IN ("
For i = 0 To lstStatus.ListCount - 1
If lstStatus.Selected(i) Then
strWhere = strWhere & "'" & lstStatus.Column(0, i) & "', "
End If
Next i
strWhere = Left(strWhere, Len(strWhere) - 2) & ")"
End If
End If

Thanks for your help!

William


Nov 12 '05 #2
I realized that my earlier suggestion for an option group may not be
the best solution if your list of status options will grow over time.
In that case, why not search for null values when nothing is selected
in the list:

If IsNull(lstStatus) Then strWhere = "Status IS NULL"

That still may not be terribly intuitive, so you might consider adding
a "(none)" entry to the list and using that selection to search for
Status IS NULL. But what happens if someone selects both (none) and a
valid status?. That's also not very friendly. Perhaps a combination
of check box and your list will work. The check box is labelled "No
status" and when checked you disable the listbox. HTH

Rick Collard
www.msc-lims.com

On Thu, 26 Feb 2004 11:33:47 -0500, "William Wisnieski"
<ww********@admissions.umass.edu> wrote:
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 boxes [lstStatus] contains two values: Call Back and No
Answer. The user can select either one or both and the proper results are
returned. If the user doesn't use this list box, then all Call Backs, No
Answers, and Null values are returned. As another option, I would like the
user to be able to select ONLY those records where the value of the field is
Null.

What code could I add to do that? Here is what I have that works as stated
above:

If Me!lstStatus.ItemsSelected.Count > 0 Then
If Len(strWhere) > 0 Then
strWhere = strWhere & "AND" & "[Status] IN ("
For i = 0 To lstStatus.ListCount - 1
If lstStatus.Selected(i) Then
strWhere = strWhere & "'" & lstStatus.Column(0, i) & "', "
End If
Next i
strWhere = Left(strWhere, Len(strWhere) - 2) & ")"
Else
strWhere = strWhere & "[Status] IN ("
For i = 0 To lstStatus.ListCount - 1
If lstStatus.Selected(i) Then
strWhere = strWhere & "'" & lstStatus.Column(0, i) & "', "
End If
Next i
strWhere = Left(strWhere, Len(strWhere) - 2) & ")"
End If
End If

Thanks for your help!

William


Nov 12 '05 #3
Thanks Rick. I like your suggestion to add an additional entry to the list
box, which I've done (No Status). But I can't figure out how to insert the
necessary code into my existing code from my first post. I was thinking
something like:

If Me.Status.Selection = 'No Status' Then strWhere = [Status] IS NULL

I just don't know how to incorporate this into the existing code.

Thanks again,

William
"Rick Collard" <no****@nospam.nospam> wrote in message
news:40**************@news.west.earthlink.net...
I realized that my earlier suggestion for an option group may not be
the best solution if your list of status options will grow over time.
In that case, why not search for null values when nothing is selected
in the list:

If IsNull(lstStatus) Then strWhere = "Status IS NULL"

That still may not be terribly intuitive, so you might consider adding
a "(none)" entry to the list and using that selection to search for
Status IS NULL. But what happens if someone selects both (none) and a
valid status?. That's also not very friendly. Perhaps a combination
of check box and your list will work. The check box is labelled "No
status" and when checked you disable the listbox. HTH

Rick Collard
www.msc-lims.com

On Thu, 26 Feb 2004 11:33:47 -0500, "William Wisnieski"
<ww********@admissions.umass.edu> wrote:
Hello Everyone,

I have a query by form with several list boxes. The user selects items fromthe list boxes and clicks a button that returns results in a datasheet
subform.

One of the list boxes [lstStatus] contains two values: Call Back and No
Answer. The user can select either one or both and the proper results arereturned. If the user doesn't use this list box, then all Call Backs, No
Answers, and Null values are returned. As another option, I would like theuser to be able to select ONLY those records where the value of the field isNull.

What code could I add to do that? Here is what I have that works as statedabove:

If Me!lstStatus.ItemsSelected.Count > 0 Then
If Len(strWhere) > 0 Then
strWhere = strWhere & "AND" & "[Status] IN ("
For i = 0 To lstStatus.ListCount - 1
If lstStatus.Selected(i) Then
strWhere = strWhere & "'" & lstStatus.Column(0, i) & "', "
End If
Next i
strWhere = Left(strWhere, Len(strWhere) - 2) & ")"
Else
strWhere = strWhere & "[Status] IN ("
For i = 0 To lstStatus.ListCount - 1
If lstStatus.Selected(i) Then
strWhere = strWhere & "'" & lstStatus.Column(0, i) & "', "
End If
Next i
strWhere = Left(strWhere, Len(strWhere) - 2) & ")"
End If
End If

Thanks for your help!

William

Nov 12 '05 #4
How about something like this:

If Me!lstStatus.ItemsSelected.Count > 0 Then
strStatus = "[Status] IN ("
For i = 0 To lstStatus.ListCount - 1
If lstStatus.Selected(i) Then
If lstStatus.Column(0, i) = "No Status" Then
strStatus = "[Status] IS NULL"
Exit For
End If
strStatus = strStatus & "'" & _
lstStatus.Column(0, i) & "', "
End If
Next i
If strStatus <> "[Status] IS NULL" Then _
strStatus = Left(strStatus, Len(strStatus) - 2) & ")"

If Len(strWhere) > 0 Then
strWhere = strWhere & " AND " & strStatus
Else
strWhere = strStatus
End If
End If

Give that a try.

Rick Collard
www.msc-lims.com
On Mon, 1 Mar 2004 16:55:21 -0500, "William Wisnieski"
<ww********@admissions.umass.edu> wrote:
Thanks Rick. I like your suggestion to add an additional entry to the list
box, which I've done (No Status). But I can't figure out how to insert the
necessary code into my existing code from my first post. I was thinking
something like:

If Me.Status.Selection = 'No Status' Then strWhere = [Status] IS NULL

I just don't know how to incorporate this into the existing code.

Thanks again,

William


Nov 12 '05 #5
Rick,

Thank you very much for the code. It works great. But what you said may
happen sure did. If I click on "No Status" and "No Answer", then the
results are only those with Null values as the status. I'm hoping I can
tweak this so that it will return both those with Null values AND the "No
Answer" value.

Thanks again for your help with this.

William
"Rick Collard" <no****@nospam.nospam> wrote in message
news:40***************@news.west.earthlink.net...
How about something like this:

If Me!lstStatus.ItemsSelected.Count > 0 Then
strStatus = "[Status] IN ("
For i = 0 To lstStatus.ListCount - 1
If lstStatus.Selected(i) Then
If lstStatus.Column(0, i) = "No Status" Then
strStatus = "[Status] IS NULL"
Exit For
End If
strStatus = strStatus & "'" & _
lstStatus.Column(0, i) & "', "
End If
Next i
If strStatus <> "[Status] IS NULL" Then _
strStatus = Left(strStatus, Len(strStatus) - 2) & ")"

If Len(strWhere) > 0 Then
strWhere = strWhere & " AND " & strStatus
Else
strWhere = strStatus
End If
End If

Give that a try.

Rick Collard
www.msc-lims.com
On Mon, 1 Mar 2004 16:55:21 -0500, "William Wisnieski"
<ww********@admissions.umass.edu> wrote:
Thanks Rick. I like your suggestion to add an additional entry to the listbox, which I've done (No Status). But I can't figure out how to insert thenecessary code into my existing code from my first post. I was thinking
something like:

If Me.Status.Selection = 'No Status' Then strWhere = [Status] IS NULL

I just don't know how to incorporate this into the existing code.

Thanks again,

William

Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Dave Karmens | last post by:
If I have say 10 fixed variables, how can I set their values = to that of a form that is built dynamically? column1 column2 email = formvalue(0) fname = formvalue(1) lname = formvalue(2)...
5
by: James Baker | last post by:
I have a form that has a dropdown list that will cause a post to the same page when it's changed. The problem I'm running into is that all of the controls reset to their default values (obviously...
1
by: raj | last post by:
hi, my list box in the html page contains list box with values. these values inturn have subvalues and I have to allign the child values to right so that i can know the parent of the values. how...
4
by: Regena | last post by:
hi, my list box in the html page contains list box with values. these values inturn have subvalues and I have to allign the child values to right so that i can know the parent of the values. how...
2
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs,...
1
by: assgar | last post by:
Hi I need help solving a porblem. I have a form that displays a checkbox, service code, description and dropdown with fees on each row. The fee_money and unit array only returns a...
2
by: mvlt | last post by:
I am using Access 2003 and working on a query by form. I have a form with two unbound combo boxes. The form searches our contact list for people in a certain renewal cycle. It then gives the...
0
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me...
3
ADezii
by: ADezii | last post by:
Null as it relates to database development is one of life's little mysteries and a topic of total confusion for novices who venture out into the database world. A Null Value is not zero (0), a zero...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.