473,396 Members | 2,151 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.

Bypass Query Parameters

Hi,

I wonder if someone might be able to help me please.

I'm fairly new to MS Access, and everything I know is self taught so please
bear with me.

I have put together a query which consists of a few fields. Some of these
have parameters which I've added to them. This in turn feeds a report.

The problem I have is that I don't always want to key in the parameters i.e.
I want to see all the data instead of it being filtered.

I have seen a very similar post on this site, with a possible solution, but
for the life of me can't get it to work i.e. where I can just click 'Go' and
it gives me all the data, but by typing in the parameters it give me the
filtered data. I just wondered whether someone could provide me with a bit of
guidance please.

The code is:

Like IIf([Year] Is Null,"*",[Year])

Where 'Year' is the field name. I have then changed this to 'Surname',
'Forename' and so on and so forth for my other fields and I have typed this
into each criteria line for the different fields.

I get all the data when I don't key the parameters in, which is obviously
what I want, but when I do I can't get the filtered data.

Any ideas please?

Regards

Chris

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200801/1

Jan 16 '08 #1
4 2345
In your original query, go to the sql view. It will say something like

Select * from tblx where somefield=[yourparam]

All you need to do is change the = sign to the word Like (and have
spaces between -- fieldname -- Like -- [Parameter])

Select * from tblx where somefield Like [yourparam]

Now when the parameter box comes up you can type in part of a param like

bill*

to get just everyone named Bill or you can type just

*

to get everything

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jan 16 '08 #2
Rich,

That's great.

I've been working on this for a while now so I really appreciate your help.
I'm not that good at writing in SQL, but using the design mode I've got it to
work:

It works a treat.

Thanks very much for your time and help.

Regards

Chris

Rich P wrote:
>In your original query, go to the sql view. It will say something like

Select * from tblx where somefield=[yourparam]

All you need to do is change the = sign to the word Like (and have
spaces between -- fieldname -- Like -- [Parameter])

Select * from tblx where somefield Like [yourparam]

Now when the parameter box comes up you can type in part of a param like

bill*

to get just everyone named Bill or you can type just

*

to get everything

Rich
--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200801/1

Jan 16 '08 #3
The above method works OK so long as you have values in those fields.
If the field is null, the * will not return that record in the search
results. You can get around that by making sure none of the fields are
null. If the field must be blank, you can set the field to accept zero
length strings and then make sure that all blank fields are set to "".

That being said, it is still a rather crude way of doing it. If you
have a lot of records, it can also take longer for the query to run as
you have unnecessary criteria in there. If you have a lot of records,
or if you have users who are not computer savvy, I find it best to
create a form that has the search fields in it along with a 'Search'
button. The user fills in the form and then clicks search. In that
search button, you 'assemble' the SQL statement into a string based on
which fields the user indicated they want to search by, then set that
string as the reports record source. If you don't know SQL, you can
copy and paste it from the query builder in SQL view to help you.
Jan 16 '08 #4
Andy,

Thanks for this, do you know I found this to be the very problem today, and
as you suggested I added 0's to those fields that didn't contain data.

However I want to learn more so I think I'll have a go at the form, it may
take a while because of other work commitments but I'll get back you to you.

There is another thing that you may be able to help me with though if that's
ok, it's something I came across today.

I have a date field where usually I would set a date partamter for the user i.
e. Between[Enter the first date] And [Enter the last date] so they can put a
from and to date in to filter the records.

Using the same prinicpal of the 'Like IIf' coding, is there anyway that I can
incorporate the two i.e the user has the option of bypassing the parameters,
but entering them if they need to filter the data.

I've been trying all afternoon, moving the Between and And around the coding,
but I just haven't got anywhere.

Any ideas please.

Kind regards and thanks

Chris

An***********@bcbsmn.com wrote:
>The above method works OK so long as you have values in those fields.
If the field is null, the * will not return that record in the search
results. You can get around that by making sure none of the fields are
null. If the field must be blank, you can set the field to accept zero
length strings and then make sure that all blank fields are set to "".

That being said, it is still a rather crude way of doing it. If you
have a lot of records, it can also take longer for the query to run as
you have unnecessary criteria in there. If you have a lot of records,
or if you have users who are not computer savvy, I find it best to
create a form that has the search fields in it along with a 'Search'
button. The user fills in the form and then clicks search. In that
search button, you 'assemble' the SQL statement into a string based on
which fields the user indicated they want to search by, then set that
string as the reports record source. If you don't know SQL, you can
copy and paste it from the query builder in SQL view to help you.
--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200801/1

Jan 17 '08 #5

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

Similar topics

5
by: Bruno Alexandre | last post by:
Hi guys, withou using SP, I want to be able to add a Parameter to the SQL Query and retrive the Recordset so I can use the Paging property under the recorset object.... how can I do this? I'm...
3
by: Ryan Hubbard | last post by:
I would like to run a query from VBA. The query will be one with parameters. Is there a way to run the query and have Access prompt for the values like it does if I where to execute it through...
5
by: Ryan Hubbard | last post by:
Is it possible to get the recordset from an open query window? So you run the query. The window is open. Can vba retrieve this data?
4
by: Lightning Tony | last post by:
This is probably a really silly question but I am exhausted and cant seem to find the answer. I have a query that I run from a command button on a form. The query has three criteria set. The first...
3
by: tdmailbox | last post by:
I set up my code to disable the shift bypass however for certain users I want to allow them through a button no a form to be able open up the list of tablies and queries. Is there a vb command...
15
by: Richard Hollenbeck | last post by:
I tried to ask this question before on the 14th of January but I never got a reply. I'm still struggling with the problem. I'll try to rephrase the question: I have a crosstab query with rows...
9
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped....
3
by: Richard Hollenbeck | last post by:
I am very sorry about the (almost) re-post, but you will see that my first question wasn't very clear; I have another question I posted this morning called, "in DAO: Run time error 3061 Too few...
3
by: CanuckChuck | last post by:
I have a code for enabling a command button to password protect the enabling/disabling of the Shift bypass. For some reason though I keep recieving a syntax error when I try to use it. I copied the...
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: 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
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
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
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.