473,394 Members | 2,090 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.

Query criterium on a number, using Like..& "*" does not work...

64 64KB
Hi,

I have a split form "frm_trajecten" with a few comboboxes to select the records which should be displayed in the lower part of the plit form.
One of the combo's is "cmb_prodjr"
It listst the years in the field [prodjaar] in the table "tbl_trajecten" trough a query called "Q_prodjaar" with unique values.
It lists;

empty
2012
2013
2014
2015

In the table "tbl_trajecten" the field [prodjaar] can be empty or filled with a number (year i.e. 2012).

Now, in the Query "Q_trajectne" (which is the bases for the form "frm_trajecten" i put in all fields of the table "tbl_trajecten". In the criteria part of the query, at the field "prodjaar" i have put in;

Expand|Select|Wrap|Line Numbers
  1. Like [Forms]![frm_trajecten]![cmb_prodjr] & "*"
This does not work properly.
When i select a year in the combobox [cmb_prodjr] it works fine.

However, when i leave the combobox empty, it does not do anything. I would then like to have it list all records.

Apparantly the & "*" part of the criteria does not work.

What should i put there instead ?

I hope to hear from you.
Pierre
Apr 17 '13 #1
6 1285
G'd Morning Pierkes,
If your combobox list the option "Empty" then your query is working properly, because what your sql query gets it's something like this:
Select a,b,c from tbl Where b Like "Empty*".
If b contains nothing but numbers the query should return just one row where the "empty" value was found.
If it doesn't, test your query by manually supplying the parameters if it works then double check the parameters you're sending via your combo.
G'd Luck

Estuardo
http://www.accessextended.com
Apr 17 '13 #2
Pierkes
64 64KB
Hi Estuardo,

Thanks for your reply. however, i don't seem able to figure it out.

when i leave out the & "*" part of the formula in the criterium part of the query and only have

Expand|Select|Wrap|Line Numbers
  1. Like [Forms]![frm_trajecten] ![cmb_prodjr]
it works fine if i select a number from the combobox (a year).

However, when the split form is displayd on opening of the form, i only see the records that contain a number in the field [tr_prod_jaar]. This is strange to me because i did not put in an on_open event.

So my guess is the query does not list the right records to begin with.

Any ideas ?
regards,

Pierre
Apr 17 '13 #3
Rabbit
12,516 Expert Mod 8TB
The problem is that when you leave it empty, the value is null, not a blank string. And a null operated on in any way with another operand results in a null. So what you really end up with is like null. Use the Nz function to convert your null into a blank string.
Apr 17 '13 #4
Pierkes
64 64KB
Hi,

I tested the following in the criterium part

Expand|Select|Wrap|Line Numbers
  1. Like [Forms]![frm_trajecten]![cmb_prodjr] & "*"
this returns all records where there is a number in the field [tr_prod_jaar] or, if i choose a year from the combobox [cmb_prodjr], it returns only the records of that year.

this is perfect.

However, if the combobox is empty, i would like the query to return ALL records, regardsless of something is filled in the field [tr_prod_jaar].

Then i tested;

Expand|Select|Wrap|Line Numbers
  1. Like [Forms]![frm_trajecten]![cmb_prodjr] OR Is Null 
If i choose a year from the combobox [cmb_prodjr], it returns the records of that year AND the records where nothing is filled in the field [tr_prod_jaar].

So this does not work either...

How do i do this ?
Please help, it's frustrating !

Thanks,
Pierre
Apr 17 '13 #5
Pierkes
64 64KB
Hi,

I found a solution;

In the query i made an extra field using the expression;

Expand|Select|Wrap|Line Numbers
  1. productiejr: IIf(IsNull([tr_prod_jaar]);"empty";[tr_prod_jaar])
This makes sure that all the records have something in the field "productiejr"

Then i can search for the item that is selected in the combobox by using;

Expand|Select|Wrap|Line Numbers
  1. Like [Forms]![frm_trajecten]![cmb_prodjr] & "*"
I now can:

- choose a item from the combobox and it will list only those records or
- choose the blank (or click a button that uses "*" to filter the records) to not use a filter

Best regards,
Pierre

P.S. If you know a more easy way, please let me know !

It works like a charm !
Apr 17 '13 #6
Rabbit
12,516 Expert Mod 8TB
You don't need to make an extra field, you can just use:
Expand|Select|Wrap|Line Numbers
  1. Like Nz([Forms]![frm_trajecten]![cmb_prodjr], "") & "*"
Apr 17 '13 #7

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

Similar topics

5
by: Dave Harrison | last post by:
Im sure this is a really obvious problem but : self.curs.execute( """SELECT * FROM user WHERE login LIKE '%%s%'""", ) will not work ... gives me an "unsupported format character ''' (0x27)"...
0
by: Ed | last post by:
------=_NextPart_000_001D_01C34FCC.1D2B5E50 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable There seems to be a significant penalty imposed by the...
12
by: Niall Porter | last post by:
Right this has to be a Micro$oft mess-up surely...? I'm running SQL 2k standard with SP3. I have a table which I'm trying to query using a LIKE operator on a varchar field as follows .......
0
by: Winterminute | last post by:
I am trying to read a list of install programs using WMI with ASP.NET/C#. However, it fails with "Invalid Class". I have confirmed that if I query LOCALHOST then it works fine, but if I query a...
9
by: Nathan Sokalski | last post by:
I am trying to do a database search using LIKE using the following code: Private Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click If...
1
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am...
0
by: steinerh | last post by:
Hi, I am using FSO (VB6.0 proff) to retrieve the serial number of my hardisk. Comparing the number with what WIN XP returns and also what I retrieve using the dir command in DOS is really...
0
by: govindrjujare | last post by:
I have a column in db2 with an index. When I search using LIKE predicate, sometimes it gives results very slow (about 3 to 5 mins). But after the initial hit, subsequent searches using different...
1
by: zmunoz | last post by:
I am working on a script using ADSI via COM in PHP. The script works for the most part when I query a user using the following function: function passwordExpires($userDN) { $comLDAP = new...
3
by: dmorand | last post by:
I've got a table which contains some items that I need to compare against another table which contains a more detailed look at the items, and there could be multiple. Example: Table1: Field:...
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
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
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
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...

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.