473,387 Members | 1,798 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,387 software developers and data experts.

How to return all records when the user does not make a selection from a list box?

I am using a list box to allow a user to select which region they want to see. My problem is when the user does not make a selection and wants to see all records.
This is the statement I'm using as the criteria expression in the Access query.

Expand|Select|Wrap|Line Numbers
  1. IIf(Not IsNull([Forms]![frm_SelectData]![lst_region]),([Forms]![frm_SelectData]![lst_region]),(Like "*")) 
  2.  
Nov 1 '10 #1
5 1784
NeoPa
32,556 Expert Mod 16PB
What do you want to see where?
Nov 1 '10 #2
dsatino
393 256MB
Unfortunately, you can't do it like this. The basic reason is this:

Behind the design view of the query, Access is building the SQL. When you put something in this criteria line Access must make a decision on what comparison operator to use in the WHERE or HAVING clause of the SQL.

By default it's going to use "=", but if comes across "Between", "Like", "Not", etc., it will use those instead.

This would seem to make your method viable on the surface, but there is a problem. Access makes it's decision on the comparison operater prior to evaluating the function you have in the criteria field.

So the SQL generated when no record is selected ends up looking something like this:

WHERE table.field = Like "*"

Which causes a syntax error or something of that sort.

Your best bet is probably to build the QueryDef or recordsource dynamically, but if it's a shared item in a multiuser environment you're going to have issues.
Nov 1 '10 #3
NeoPa
32,556 Expert Mod 16PB
My question wasn't an idle one. The correct answer to this question depends entirely what the actual question is. There are at least two different scenarios I can imagine you're talking about, and each would require a very different response.

It really is very important to get your question to make sense before posting it, otherwise you can find all sorts of problems (and it wastes everybody's time).

DSatino's post handles one of the possible scenarios. Is it the one you're thinking of? Who can say.
Nov 1 '10 #4
I'm trying to let the user select what they want to see in a number of Listboxes. From their choices I wanted to use a query to return the results. The issue is when they don't make a selection in 1 or more of the listboxes - for instance they want to see "all" regions.
It looks like I'm going to be building the query dynamically but I thought the 1st option would be quicker and more straight forward.
I was stumpped on the IIF stnt above used in the query.

Thank you.
Nov 1 '10 #5
NeoPa
32,556 Expert Mod 16PB
Queries are funny things. People talk about queries, when often they are referring to QueryDef objects. A QueryDef is a stored query - A database object.

The reason I bring this up is that modifying QueryDefs is not so trivial, and opening a SQL query, that's not a QueryDef, for viewing the result set is not supported. This is where filters come in.

What I suggest you look into, is defining your object, a full report can more flexibly be handled than a simple QueryDef (whose open parameters are more restricted), which can be saved and which shows all possible records. From this point it can be opened with or without applying a filter (WhereCondition parameter). Your form can determine the requirement and, if a filter is required, build and apply it.

Does that sound like the sort of approach that would suit you?
Nov 1 '10 #6

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

Similar topics

5
by: Mark | last post by:
I have an application that uses PHP to access a MySQL table and extract rows which match the user's search entry. Data from the matching rows are loaded into an HTML selection list, and the user...
5
by: glin | last post by:
Hi there, does anyone know how to use smarty to generate a selection list without PHP assigning a array? eg. a list for selection minutes, but without php to assign a 1~60 array into smarty. ...
5
by: Jim Cobban | last post by:
I am trying to create a web page in which the contents of one selection list depends upon which element in another selection list is chosen, but where the information to populate the first...
3
by: Alpha | last post by:
Hi, I have a window C# application. I update the dataset when user finished entering in a text box. But when I want to update the database when OK is pressed, the...
0
by: Galina | last post by:
Hello I have an asp page, which is designed to allow selection from 5 interdependant select boxes. User selects and submits. A database is queried with selected values as parameters and another...
5
by: srampally | last post by:
I need the capabilty to hide/show a selection list, just the way its done at http://www.lufthansa.com (place the cursor over "Group Companies"). However, I am looking for a javascript that is much...
10
by: dkyadav80 | last post by:
<html> /// here what shoud be java script for: ->when script run then not display all input text field only display selection field. ->when user select other value for institute only this...
0
by: swapnil1987 | last post by:
hello friends i am trying to find solution for this problem if u know something then please tell i am creating web application that runs on black berry. here i need to create selection list...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.