I have a table TBStaff with boolean fields to show their type of employment. Staff can have many types of employment (upto 6). TBStaff
StaffID_________Autonumber (PK)
Forenames_____Text
Surname_______Text
Assessor_______yes/no
Trainer_________yes/no
IV_____________yes/no
etc.
I have a form which lists all the staff (FRMStaffList). I've put option controls on the form for the user to select which type of employment they want to see.
[O].Assessor....(control named "AssessorChosen")
[O].Trainer........(control named "TrainerChosen")
[O].IV...............(control named "IVChosen")
In the query used for FRMStaffList I could simply put the criteria for the boolean fields as Forms!FRMStaffList.AssessorChosen
i.e. -
SELECT TBStaff.Assessor, TBStaff.Trainer, TBStaff.IV
-
FROM TBStaff
-
WHERE (((TBStaff.Assessor)=[Forms]![FRMStaffList].[AssessorChosen]) AND
-
((TBStaff.Trainer)=[Forms]![FRMStaffList].[TrainerChosen]) AND
-
((TBStaff.IV)=[Forms]![FRMStaffList].[IVChosen]));
-
However, if I do this for all employment types the query will only look for single employment types.
Consider example below: - Name Assessor Trainer IV
-
Bill Hicks True
-
Bill Bailey True True
-
Bill Gates True True
-
Bill Murry True
-
If I wanted to show just Assessors the query will will evaluate as -
SELECT TBStaff.Assessor, TBStaff.Trainer, TBStaff.IV
-
FROM TBStaff
-
WHERE (((TBStaff.Assessor)=TRUE) AND
-
((TBStaff.Trainer)=FALSE]) AND
-
((TBStaff.IV)=FALSE));
-
This will show only Bill Hicks and not Bill Bailey and Bill Gates.
I tried to use an IIF statement to choose the criteria statement based on the options the user chooses.
e.g. -
SELECT TBStaffTmp.TBStaffID, TBStaffTmp.Forenames, TBStaffTmp.Assessor, TBStaffTmp.Trainer, TBStaffTmp.IV
-
FROM TBStaffTmp
-
WHERE (((TBStaffTmp.Assessor)=IIf([Forms]![FRMStaffListTMP].[AssessorChosen]=True,True,True Or False)) AND
-
((TBStaffTmp.Trainer)=IIf([Forms]![FRMStaffListTMP].[TrainerChosen]=True,True,True Or False)) AND
-
((TBStaffTmp.IV)=IIf([Forms]![FRMStaffListTMP].[IVChosen]=True,True,True Or False)));
-
But this doesn't work, can IIF statements even be used in this way?
Of course I guess I could create a different query based on the options the user chooses but I would have to create an unbelievable amount of queries to do that.
Any help much appreciated.
Hi !
First of all, your database is as much non-normalized that not allows me to think on it.
I advice you to take a look here: http://bytes.com/topic/access/insigh...ble-structures
Anyway, I sketch a normalized database for you and I do your job (in my way, of course)
See attachment !
3 2400
OK I think I have it sorted. Not sure if this is the best way of going about this. In essence I wanted to show records from TBStaff where the boolean fields where true according to the options chosen by the user. However, passing the option control value though to the queries means passing unwanted criteria, i.e. showing records because boolean value is False.
I have created 6 queries all based on one single boolean field.
e.g. -
SELECT TBStaffTmp.StaffID, TBStaffTmp.Forenames, TBStaffTmp.Assessor, TBStaffTmp.Trainer, TBStaffTmp.IV
-
FROM TBStaffTmp
-
WHERE (((TBStaffTmp.Assessor)=[Forms]![FRMStaffListTMP].[AssessorChosen]));
-
Then - SELECT TBStaffTmp.StaffID, TBStaffTmp.Forenames, TBStaffTmp.Assessor, TBStaffTmp.Trainer, TBStaffTmp.IV
-
FROM TBStaffTmp
-
WHERE (((TBStaffTmp.Trainer)=[Forms]![FRMStaffListTMP].[TrainerChosen]));
and - SELECT TBStaffTmp.StaffID, TBStaffTmp.Forenames, TBStaffTmp.Assessor, TBStaffTmp.Trainer, TBStaffTmp.IV
-
FROM TBStaffTmp
-
WHERE (((TBStaffTmp.IV)=[Forms]![FRMStaffListTMP].[IVChosen]));
-
e.c.t.
I then used a union query to put the records together. However, I only want to union the tables if the relevant option has been chosen by the user.
For example, if user chooses to view IV's only then the first query will evaluate to -
SELECT TBStaffTmp.TBStaffID, TBStaffTmp.Forenames, TBStaffTmp.Assessor, TBStaffTmp.Trainer, TBStaffTmp.IV
-
FROM TBStaffTmp
-
WHERE (((TBStaffTmp.Assessor)=FALSE));
-
This would show record BILL MURRY as that record does have TBStaffTmp.Assessor value of False.
What I have to do is Union only those records that show a relevant record. I've done this by adding a WHERE statement. - SELECT TBStaffID, Forenames, Assessor, Trainer, IV
-
FROM QYStaffListTMP1
-
WHERE Assessor = True
-
UNION ALL
-
SELECT TBStaffID, Forenames, Assessor, Trainer, IV
-
FROM QYStaffListTMP2
-
WHERE Trainer = True
-
UNION ALL SELECT TBStaffID, Forenames, Assessor, Trainer, IV
-
FROM QYStaffListTMP3
-
WHERE IV = True;
-
I then added the results of that Union query to another query run as DISTINCT as duplicate records are very likely.
I think logically that is correct, if anyone notices anything wrong with this or has a better solution please let me know.
Hi !
First of all, your database is as much non-normalized that not allows me to think on it.
I advice you to take a look here: http://bytes.com/topic/access/insigh...ble-structures
Anyway, I sketch a normalized database for you and I do your job (in my way, of course)
See attachment !
Mihail, thank you very much for your reply and attachment. I understand exactly what you are saying. That is most definitely a much better approach, a lot easier as well ;)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: JDJones |
last post by:
Using PHP and MySQL. Trying to put a list of categories into a drop down
select option of a form like:
<form name="form" action="<? print $_SERVER?>" method="get">
<select name="subject">...
|
by: Piotr Wolski |
last post by:
more or less that is my problem:
i'm making HTML <select><option> statement:
if ($dir = @opendir("/the/directory)) {
while($file = readdir($dir)) {
echo '<option value="'.$file.'">'.$file;...
|
by: RICHARD BROMBERG |
last post by:
I am using MS Access 2000 and crating an application where the main table
has about 90 fields.
I understand how to run a where the value of a PARTICULAR field is entered
into a text box.
I want...
|
by: Stijn Vanroye |
last post by:
Hi List,
I'm running a query on a not-so-small db. Mostly this query runs fast enough, but every once in a while the query takes a long time to complete in wich case the users start banging away...
|
by: amith.srinivas |
last post by:
Hi all,
From a word macro in VBA, I am trying to create a report in
access DB. The report is based on a query with a parameter. I am using
Set rpt = Application.CreateReport
rpt.RecordSource =...
|
by: Kermit Piper |
last post by:
Hello,
I thought this should be easy, but... all I want to do is set the value
of this state drop-down based on a session var I'm getting back from a
redirect (from the processing page):
<%...
|
by: magix |
last post by:
Hi,
in my SELECT (like below), the option value has 2 values, separated with
comma ","
<select name="sIdName">
<option value="10,John">John</option>
<option value="11,Eva">Eva</option>...
|
by: bubbles |
last post by:
Newbie transiting from VBA to TSQL, using SQL Server 2005 Enterprise:
Need help to do this:
Open Table_A
WITH TableA
DO UNTIL .EOF
Read value from TableA.ColumnA
Run SQL Statement on...
|
by: Joe |
last post by:
This is my HTML form:
<form method=get action="home.php">
<INPUT TYPE = "Text" VALUE = "" NAME = "title"><br>
<select name="searchby">
<option value="Title">Title</option>
<option...
|
by: Karen D |
last post by:
Help Again!! I’m using Access 2003 and I have a form that allows users to enter criteria for selecting tables and queries as well as the query parameters that will be used to generate a report. The...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
| |