473,750 Members | 2,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help needed with Query criteria and combo boxes

2 New Member
Hi
I'm using Acces 2003
I have Query where the several parameters for the criteria are supplied from a form. One parameter source is a combo box. What I am trying to do is if:

An item is selected on the combo box then that value is used as the criteria

If user does not want the contents of the combo box used, then Query should ignore that field.

I have tried to do this with an iif statement in the query criteria and a control box on the form.

i.e in the criteria for that field use

iif([forms]![formname]![option10]=-1,[forms]![formname]![combo0],Like"*")

[option10] being the control

This works when the condition is true, ie a person wants to use the combo box and has selected a value. It does not work for the false condition. What I was expecting to happen is since that the control box is not selected(iif is false) all records are returned by the query using like"*".

Any suggestions, alternative approaches?

Thanks
Apr 4 '07 #1
3 2284
Rabbit
12,516 Recognized Expert Moderator MVP
Hi
I'm using Acces 2003
I have Query where the several parameters for the criteria are supplied from a form. One parameter source is a combo box. What I am trying to do is if:

An item is selected on the combo box then that value is used as the criteria

If user does not want the contents of the combo box used, then Query should ignore that field.

I have tried to do this with an iif statement in the query criteria and a control box on the form.

i.e in the criteria for that field use

iif([forms]![formname]![option10]=-1,[forms]![formname]![combo0],Like"*")

[option10] being the control

This works when the condition is true, ie a person wants to use the combo box and has selected a value. It does not work for the false condition. What I was expecting to happen is since that the control box is not selected(iif is false) all records are returned by the query using like"*".

Any suggestions, alternative approaches?

Thanks
That's because iif returns a string and a string is never evaluated. Use:
Expand|Select|Wrap|Line Numbers
  1. Like iif([forms]![formname]![option10]=-1,[forms]![formname]![combo0],"*")
Apr 4 '07 #2
ericargent
2 New Member
Hi
Thanks, But what happens now is that the false condition works and the true condition does not. It seems that for example the criteria does not evaluate

Like oven#1

the same as [forms]![formname] etc.

oven #1 being the selection from the combo box
Would the # be the problem in the value?

thanks
Apr 4 '07 #3
Rabbit
12,516 Recognized Expert Moderator MVP
The following characters would cause problems because the Like operator uses wildcards.
Expand|Select|Wrap|Line Numbers
  1. *
  2. #
  3. [ ]
  4. ?
  5. _
  6. %
  7.  
So if you want to return oven#1 then the combobox has to pass oven[#]1 to the query.
Apr 4 '07 #4

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

Similar topics

6
2132
by: EJC | last post by:
Hi Folks, I've been trying to build a query from a form of dialogue boxes I have created that holds search criteria for my main database. I have been able to get the query to retrieve the data selected in the relevant dialogue boxes and perform the query on these boxes. However my problem lies in the fact that if no choice is selected in the dialogue box I want the query to default (or get passed) a wildcard that will mean it will...
5
2200
by: Steve Patrick | last post by:
Hi All You guys are my last hope, despite spending money on books and hours reading them I still can not achieve the results I need. I have designed a database in Access 2000 based on 1 table, all has gone very well with one exception. The table is based on applications made by potential customers looking to buy franchise rights to particular locations and as part of the process they are asked to list their preferred locations 1 to 4....
3
1291
by: arthur-e | last post by:
Thanks in advance!! I've looked at fConcatFld but that doesn't seem to be what i'm looking for or I just can't figure it out. I'm trying to have a button select records based on two combo boxes - one holding a number and one text. Floor(combo18) is a floor number and site(combo20) is a building name Private Sub Command22_Click() Dim strSQL As String
4
7192
by: meganrobertson22 | last post by:
Hi Everyone- I have a question about how to add and then use the "All" selection in a combo box. I am trying to figure out how to: (1) add "All" as a selection to a combo box and then (2) how to use the selection "All" as criteria for a field in a query, which is used to generate data for a report.
12
2366
by: Tom | last post by:
Hello, I have a database of employee data in access and I am trying to create a form with combo boxes for criteria (ex. gender, office, position, etc.) that let the user select criteria from drop down menus (ex. they may select Male, New York, Manager) and those criteria will be used to run a query (ie Query by Form). I can do this with text boxes but when I tried to use combo boxes no records were returned in the query. Any idea what...
2
5738
by: Mark Roughton | last post by:
I have a form where the users need to view records for various criteria, one of which is a date field on which they may wish to view all related data for the selected date, for all dates upto and icluding the selected date or all records on or after the selected date The user selects either "=", >=" or "<=" from a combo box and then a date from another combobox. The combination of thse two choices is then set in an unbound textbox so...
5
2023
by: deaconj999 | last post by:
Hi, I have nearly finished my database and I would like to add a query that uses a combo box to get the results, not the usual paramater style input. I suppose it would need a form and a query and a combo box, but where to start !!!!!!!! Any kind soul out there that can give me an example of where to start..........?
4
3032
by: Swinky | last post by:
I am trying to make a combo box dependent on a text box. I cannot get the combo box to pull the related data from the text box. I have been all over this user group & have tried several versions of code to no avail. I would like to display all contact names (in the combo box) related to the customer number in the text box. Here's what I have:
4
1613
kcdoell
by: kcdoell | last post by:
I have a form (Form1) that displays records based on 3 unbound combo boxes that are also on my form. My record source for this form is a query “ReQryForecast” (which looks at those combo boxes via the criteria setting of that query). If changes are made to one of the combo boxes, the records displayed will change via my simple code in the after update event of my unbound combo box. This works fine…. Now I have a command button on Form1...
0
8999
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9575
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9338
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9256
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6803
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4712
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4885
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2223
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.