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

Query by form w/ null options.

Fspinelli
I have a query by form that asks for:

Start Date (field name is "txtDate1")
End Date (field name is "txtDate2")
Distributor (combo box name is "cboDist")
Client (combo box name is "cboClient")

The qeury brings up the data just fine if the end user has every field filled in, but what if Start and End dates are not needed, and/or the distribitor or client?

Any one of them with criteria in them should produce results for the end user. Well, that's my wish. However; I can only get desired results if each field has data in it.

The query has this:

Date:
Between [Forms]![frmMain]![txtDate1] And [Forms]![frmMain]![txtDate2]


Client:
[ClientName]=[Forms]![frmMain]![cboClient] Or [Forms]![frmMain]![cboClient] Is Null
(I have "true" in the criteria part of that)


Distributor:
[Distame]=[Forms]![frmMain]![cboDist] Or [Forms]![frmMain]![cboDist] Is Null
(I have "true" in the criteria part of that)

I tried "Is Null" in the Or spot of each query column, but that didn't work.

Any suggestions?

Thank you!
Aug 27 '10 #1
14 2232
Thank you for the reply, FishVal!

I think that's more than I need. There are two text boxes and two combo boxes (Value List).

I just need to make it so that any one, or all, that are filled in will produce results. For instance, if someone just wants a start date (they enter it dd/mm/yyyy) and a particular client (they would choose from the list in the combo box) then the subform populates the results. No matter if a field has something in it or not (but one of them at least has to have something.)

I hope I'm not confusing everyone too much. Can you tell I'm a beginner?
Aug 27 '10 #3
FishVal
2,653 Expert 2GB
So, this means you have 4 (even 5 taking into account the requirement that at least one of 4 controls has to be not null) conditions.
A record should be fetched if all 4(5) conditions are True. So far , so good.
Now, each condition has to be true if correspondent comparison returns True or a correspondent control value is False. An example of how it could be done is in the thread I've posted link to (msg #7).
When combining all 4(5) conditions pay attention to operator precedence (AND operation is performed before OR), so you'll need to put brackets appropriately to override default order of expression evaluation.

And the last, but not the least. If you feel it is too complicated to get it all at once, then try to make it for a single condition first, then for two and then for all the set.

Kind regards,
Fish.
Aug 27 '10 #4
NeoPa
32,556 Expert Mod 16PB
FSpinelli:
For instance, if someone just wants a start date (they enter it dd/mm/yyyy)
You need to be a little careful with dates, especially if you're using English/French format (d/m/yyyy). You can find more detail of that in Literal DateTimes and Their Delimiters (#). I think Access tries to be clever for you, but remember that TextBoxes just store their data as text. It is only converted when used. You should avoid the possibility of comparing dates as text strings as the order textually is quite different from the order expected when the data is interpreted as dates.

Talking of national formats, would it be out of order to ask why that format if you're from New York State?
Aug 27 '10 #5
Um... because? I don't have an intelligent answer for that one! (**as she crosses her eyes**)

I'm working off of someone elses work. It's already in the DB as mm/dd/yyyy (08/27/2010) so I'm just bringing that format on over into the QBF. Plus we usually put the month, the date, and the year (maybe abreviated like 8/27/10).

It's just for my small office and keeping with the current format reduces the headache I'm getting from relearning code (it's been about 18 years) and utilizing Access (remember v2? lol).

Just need those four fields (or at least one) to bring up data from a query. If it's just a start date of 2/10/2009 - then whatever broker and client along with whatever fields I chose has any relation to that start date will come up in the subform. If it's just a broker name chosen from the combo box, then everything comes up (yes, I have it grouped by whatever). If only a client, then wallah - same thing. Simple stuff.

Trying to keep it as simple as possible.

Thanks for the link - I'll be reading and trying to figure it out for sure!
Aug 27 '10 #6
NeoPa
32,556 Expert Mod 16PB
Let me start by apologising for leaving you in the wind here somewhat. I was away last week, but I'm back now.
FSpinelli:
Um... because? I don't have an intelligent answer for that one! (**as she crosses her eyes**)

I'm working off of someone elses work. It's already in the DB as mm/dd/yyyy (08/27/2010) so I'm just bringing that format on over into the QBF. Plus we usually put the month, the date, and the year (maybe abreviated like 8/27/10).

It's just for my small office and keeping with the current format reduces the headache I'm getting from relearning code (it's been about 18 years) and utilizing Access (remember v2? lol).
This response confuses me. You're describing why m/d/yyyy, but I was asking about why d/m/yyyy. The former is quite natural for someone from the USA, whereas the latter is a European format. It's only my curiosity of course, but I wondered why you would be using a European format.

FSpinelli:
Just need those four fields (or at least one) to bring up data from a query. If it's just a start date of 2/10/2009 - then whatever broker and client along with whatever fields I chose has any relation to that start date will come up in the subform. If it's just a broker name chosen from the combo box, then everything comes up (yes, I have it grouped by whatever). If only a client, then wallah - same thing. Simple stuff.
Looking at your question again, and assuming you want to work from the form directly (as you appear to be trying), I would guess you're looking for something like :
Expand|Select|Wrap|Line Numbers
  1. ...
  2. WHERE    ([ClientName] Like '*' & [Forms]![frmMain]![cboClient] & '*')
  3.   AND    ([DistName] Like '*' & [Forms]![frmMain]![cboDist] & '*')
  4.   AND    ([DateField] Between CDate(Nz([Forms]![frmMain]![txtDate1], '1/1/1900'))
  5.                           And CDate(Nz([Forms]![frmMain]![txtDate2],'12/31/9999')))
An alternative approach can be found in Cascaded Form Filtering.
FSpinelli:
Trying to keep it as simple as possible.

Thanks for the link - I'll be reading and trying to figure it out for sure!
Both wise ideas.
Sep 6 '10 #7
Thanks, Neo! I'm going to give that a try.

Any suggestion on partial matches? I have a text box where the end user can enter, for example, "Tr" (even if they use upper and/or lower case) in the Company field then click the search button. Every record that has the letters "tr" in it comes up... Not just the beginning of the name (which is what's needed).

Also, with my question, and I hope I can figure out how to ask it where it makes sense; Can I make it a combo box which also allows text (one or a few letters) in it? Another words, the user can click on the combo box and choose a specific company record from the combo box list, or, they can just enter one or several letters, click search and have the results populate. Know what I mean?

I really appreciate the guidance and imput (from everyone).
Sep 10 '10 #8
NeoPa
32,556 Expert Mod 16PB
FSpinelli:
Any suggestion on partial matches? I have a text box where the end user can enter, for example, "Tr" (even if they use upper and/or lower case) in the Company field then click the search button. Every record that has the letters "tr" in it comes up... Not just the beginning of the name (which is what's needed).
Simply remove the leading asterisk (*) characters.

EG. Line #2 would become :
Expand|Select|Wrap|Line Numbers
  1. WHERE    ([ClientName] Like [Forms]![frmMain]![cboClient] & '*')
FSpinelli:
Also, with my question, and I hope I can figure out how to ask it where it makes sense; Can I make it a combo box which also allows text (one or a few letters) in it? Another words, the user can click on the combo box and choose a specific company record from the combo box list, or, they can just enter one or several letters, click search and have the results populate. Know what I mean?
I believe you can set up a ComboBox so that it allows entries that are not found in the list (Limit To List = No). This should allow what you need. Give it a try.
Sep 10 '10 #9
Thank you!

I must be doing something wrong again. I tried what you said and I get a syntax error and my query won't save.

So this is the code I have currently:

[Company] Like "*" & [Forms]![frmSearch]![TxtCompany] & "*" or [Forms]![frmSearch]![txtCompany] Is Null

Do I have to put some sort of code before the first Like "*" to make it only choose the beginning letters of a field, not just any letters that match?
Sep 10 '10 #10
NeoPa
32,556 Expert Mod 16PB
I don't know where you got that from. It's quite different from anything I suggested.

What you need is simply :
Expand|Select|Wrap|Line Numbers
  1. ([Company] Like [Forms]![frmSearch]![TxtCompany] & '*')
Sep 10 '10 #11
Yay! It works! You're the best!!!
Sep 10 '10 #12
NeoPa
32,556 Expert Mod 16PB
Always glad to help :)
Sep 11 '10 #13
Good morning NeoPa!

So I thought I was rockin'n-rolling until different tests out using various dates, with or without Broker(s) and/or with or without Client(s).

The Beginning and Ending dates are required. (this works)
Broker is not required but is a choice (value list)
Client is not required but is a choice (value list)

Here is the code in my query:

Beginning and End Dates are based off of the Date field:

Criteria: Between [Forms]![frmTradeMain]![txtDate1] And [Forms]![frmTradeMain]![txtDate2] Or Is Null
Or: Is Null
(I don't know why "Is Null" in there twice, Access did it, not me.)

Broker:
[Forms]![frmTradeMain]![cboBroker] Or [Forms]![frmTradeMain]![cboBroker] Is Null
Criteria: is set to True
(Or: does not have Is Null because even when I put it in there it doesn't work)

Client:
[Forms]![frmTradeMain]![cboClient] Or [Forms]![frmTradeMain]![cboClient] Is Null
Criteria: is set to True
(Or: does not have Is Null because even when I put it in there it doesn't work)

Dates work, but I can't get (Only the results) for the chosen broker and/or client.

Help?
Sep 13 '10 #14
NeoPa
32,556 Expert Mod 16PB
This is hard to work with as I'm still short of information. Try popping the SQL in here and I'll work to that.
Sep 13 '10 #15

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

Similar topics

3
by: Mike Cocker | last post by:
Hello, I'm quite weak at PHP, so I was hoping to get some help understanding the below code. First off, I'm trying to create a "query form" that will allow me to display the results on my...
13
by: dogu | last post by:
Noob alert. Code is below. File is saved as a .php. What I'm trying to do: User uses 'select' box drop down list to pick a value. Value ($site) is derived from a db query. This works fine....
3
by: Harvey | last post by:
Hi, I try to write an asp query form that lets client search any text-string and display all pages in my web server that contain the text. I have IIS 6.0 on a server 2003. The MSDN site says...
1
by: Dman | last post by:
MS Access 2002 - query form control returns funny symbols like I am running an append query on a form. Access is having trouble with the calculated fields and comboboxes. Example – referring...
1
by: Macbane | last post by:
Hi There, I have a main form that with a subform which is based on a parameter query. I have 2 controls on the main form & which are used as parameters in the query. It all works fine and...
10
by: FNA access | last post by:
Hello to the world of the wise, I am a CSOM student at TRU. I am trying to design a database to improve my understanding. The problem I am having is with setting up a query. I have a Query...
7
by: bluray | last post by:
I have been fighting with this for a while, and I know someone on this board will be able to figure it out in a split second :) I have a List Box and a Combo Box. Based on the selection the user...
8
by: ndeeley | last post by:
Hi, My database user has just decided that a recent text field in my database needs to be numeric so that some calculations can be run. I've changed it to a double so I can keep the point...
4
by: student2 | last post by:
Hi :-) I've designed a query that gathers its information for two tables:- 1)Author and 2) Category My selection criteria for this query is Author.AuthorName and Category.CategoryName .
11
beacon
by: beacon | last post by:
Hi everybody, I created a database that links one table from an ODBC data source. I saved my password and UID to the data source so neither myself nor anyone else would have to login each time...
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: 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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.