Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old June 27th, 2008, 08:22 PM
Coll
Guest
 
Posts: n/a
Default Using a control on a form to determine criteria for a query

I have a form and a query. I would like to have some control on the
form (check box probably), that when selected will limit the criteria
for a field in a query. Here are the details....

When the checkbox (or whatever control is appropriate on the form) is
checked, the field "employment_category" in my query will have the
following criteria - not "temp" and not "diem" - I've tried several
things, but I can't seem to figure out how to feed the criteria for
that field. Any suggestions?

Colleen
  #2  
Old June 27th, 2008, 08:22 PM
Albert D. Kallal
Guest
 
Posts: n/a
Default Re: Using a control on a form to determine criteria for a query

"Coll" <col_mcmanus@hotmail.comwrote in message
news:fcc7a545-4c5a-4775-b4ae-4dbe96dbd9c9@f36g2000hsa.googlegroups.com...
Quote:
>I have a form and a query. I would like to have some control on the
form (check box probably), that when selected will limit the criteria
for a field in a query. Here are the details....
>
When the checkbox (or whatever control is appropriate on the form) is
checked, the field "employment_category" in my query will have the
following criteria - not "temp" and not "diem" - I've tried several
things, but I can't seem to figure out how to feed the criteria for
that field. Any suggestions?
>
Your request is a little bit more difficult. If it was "just" ONE condition,
it would be quite easy.
You would simply place the form name + control name right into the query
builder in the condition area.

In your case, we have to solve a few problems.

If the check box is NOT checked, then I assume you do NOT want the
conditions (the report will ignore..or show all).

Checking "one" checkbox to do "two" conditions will require you to write
some code.

The idea would be build form with a heck box. (and, a button to "launch" the
report.

The code behind our button to launch the form would be:

dim strWhere as string

if me.MyCheckBox = true then
strWhere = "employment_category <'not temp'" & _
" and employment_category <'diem'"
end if

docmd.OpenReport "nameOfReport",acViewPreview,,strWhere

Note that the above will NOT include records where employment_category is
blank.

In the above you have to replace "myCheckBox" with the name of your check
box.

The above is likely the approach I would use, but it does mean you have to
write a bit of code...

Here is some more screen shots which use the above idea for reports:

http://www.members.shaw.ca/AlbertKal.../ridesrpt.html


--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKallal@msn.com


  #3  
Old June 27th, 2008, 08:22 PM
Coll
Guest
 
Posts: n/a
Default Re: Using a control on a form to determine criteria for a query

On Apr 19, 9:58*pm, "Albert D. Kallal" <PleaseNOOOsPAMmkal...@msn.com>
wrote:
Quote:
"Coll" <col_mcma...@hotmail.comwrote in message
>
news:fcc7a545-4c5a-4775-b4ae-4dbe96dbd9c9@f36g2000hsa.googlegroups.com...
>
Quote:
I have a form and a query. I would like to have some control on the
form (check box probably), that when selected will limit the criteria
for a field in a query. Here are the details....
>
Quote:
When the checkbox (or whatever control is appropriate on the form) is
checked, the field "employment_category" in my query will have the
following criteria - *not "temp" and not "diem" - I've tried several
things, but I can't seem to figure out how to feed the criteria for
that field. Any suggestions?
>
Your request is a little bit more difficult. If it was "just" ONE condition,
it would be quite easy.
You would simply place the form name + control name right into the query
builder in the condition area.
>
In your case, we have to solve a few problems.
>
If the check box is NOT checked, then I assume you do NOT want the
conditions (the report will ignore..or show all).
>
Checking "one" checkbox to do "two" conditions will require you to write
some code.
>
The idea would be build form with a heck box. (and, a button to "launch" the
report.
>
The code behind our button to launch the form would be:
>
dim * strWhere * * * *as string
>
if me.MyCheckBox = true then
* *strWhere = "employment_category <'not temp'" & _
* * * * * * * " and employment_category <'diem'"
end if
>
docmd.OpenReport "nameOfReport",acViewPreview,,strWhere
>
Note that the above will NOT include records where employment_category is
blank.
>
In the above you have to replace "myCheckBox" with the name of your check
box.
>
The above is likely the approach I would use, but it does mean you have to
write a bit of code...
>
Here is some more screen shots which use the above idea for reports:
>
http://www.members.shaw.ca/AlbertKal.../ridesrpt.html
>
--
Albert D. Kallal * *(Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKal...@msn.com
Thank you. One more question - just to complicate things a bit further
- if the box is checked, there are 4 possible field values that I
would want to exclude. Three of them include the word *temp* - can I
use your code with the wildcards or do I need to spell out each of
those 3 values. Also, I am opening a query rather than a report - it's
a data dump for users to then export to Excel - I'm assuming that
wouldn't cause any problems,and the code will still work with
docmd.openquery...?
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles