Using checkbox to filter query Access - ms-access

I'm VERY new to working with Access, and SQL--thank you for your patience with me! I'm working on a query based off of an inventory table:
tblInvnetory:
recordID (PK),
itemID,
setID,
other fields with info specific to item
Not all items have a setID. I would like to have a checkbox on the form with the other search parameters to filter out records that include a setID (e.g. include items from sets). So if box is TRUE = return records with setID. If box is FALSE = return records with no setID.
Would an IIF statement accomplish this? If so, any guidance on what the syntax would look like?
The other thought I've had is to include a checkbox in tblInventory that is "Item is part of Set". So if in the table it is true, and the box on the form is true, it will only return records with a setID. Would I also need an IIF statement for that scenario?

It could be a job for Xor:
Where [Forms]![FormName]![CheckboxName] Xor Not (SetID Is Null)

Related

De-duplicating based off two fields in Tableau Prep

If I have the following data with two fields, Person ID and Action Date:
Example Data
I want to remove duplicate ID rows but keep the row with the latest date.
I have tried various calculated filters based around COUNTD but honestly getting very confused.
Create calculated field [Filter]:
{FIXED [Person ID]: MAX([Action Date])} = [Action Date]
then place it on a filter shelf, selecting only True values. Finally right click this pill on filter shelf and select Add to context
In Tableau Prep, use the Aggregate step. Put Person ID in Grouped Fields and Action Date in Aggregated Fields. Choose MAX for the operation in Aggregated Fields.
Try this:
Create a calculated field and write below table calculation:
IF WINDOW_MAX(MAX([Action Date])) = MAX([Action Date])
THEN TRUE
ELSE FALSE
END
Compute the table calculation as Specify Dimensions and reset for every ID
Now use this in filter and check True

IIF statement to return 1 or all based on criteria

I'm building a form in Access to return a list of projects with different completion states [project_state]. On the form, the user can select to view All projects or projects assigned to a particular team. Then user can select in a combo box [Combo100PStatus] on that same form to filter these results by project state. Onclick, a query is run to return the results. In the query, I used the expression builder with the following code:
IIf([Forms]![Main]![Sub].[Form]![Combo100PStatus]="All","Like '*'",[Forms]![Main]![Sub].[Form]![Combo100PStatus])
The second half of the code works -- I can get the results to return the correct projects when one state is selected from the [Combo100PStatus] box, but is there a way to get all rows returned when "All" is selected?
The criteria operator (=, <>, LIKE, etc) cannot be dynamic.
Like IIf([Forms]![Main]![Sub].[Form]![Combo100PStatus]="All", "", [Forms]![Main]![Sub].[Form]![Combo100PStatus]) & "*"

Access Query Criteria Creating Parameter Query

I am having a problem with a query that uses iif statements per the below:
Items to Exclude: IIf([Is this FAC]="No",[ID2],IIf(([Is this FAC]="Yes") And ([ID2]="CsaId"),"False",[ID2]))
The above 'Items to Exclude' field should populate ID2 where the 'Is this FAC' field is (1) No OR (2) is Yes AND ID2 is not 'CsaId'.
When the Query is run with the above formulas and as per the below it works fine, returning FALSE where it should in the 'Items to Exclude' field per the formula.
The problem is if I then enter <>"False" in the Criteria field per the below (as I want to then filter out any exclusions, i.e. False items)
it seems to turn the field into a parameter query and gives a window pop up per the below instead of just filtering out the FALSE statements.
I would appreciate any help/ideas.
Thanks
Unfortunately in WHERE and GROUP BY clauses you cannot use column aliases like you did. Replace all Is this FAC by formula for this column. So, in your case for Items to Exclude the formula will be
Items to Exclude: IIf(IIf([Id1]="FAC","Yes","No")="No",[ID2],
IIf((IIf([Id1]="FAC","Yes","No")="Yes") And ([ID2]="CsaId"),"False",[ID2]))
After this condition will work.You can think about simplifying this formula.
Also you can save your query without criteria and then use it as subquery for filtering out unnecessary records.

Use ComboBox as Query Criteria - Boolean

I'm building a query that I'll use in a form to display a list of employees. On my form I have two comboboxes, one to filter the query by end date and one to filter by status.
The source table for the query has a Boolean field (a Yes/No field) which designates whether the employee is available or not, hence the combo to filter by status. I've run into the issue of how to use non-Boolean combo options but still have the query critera be Boolean.
I know that to use a combobox as a criteria I use this syntax: [Forms]![Form1]![Combo4], but since my combo options are "In Training" and "Available" I don't know how to convert the criteria to Boolean... is this even possible?
Example
If my user selects "In Training" from the combo (which would be equal to False on the source table), my query should use False as the criteria for that field.
After searching Google for an hour without any luck, I'm guessing this may not be possible?
Use an IIf expression to transform the combo's text value to Boolean.
IIf([Forms]![Form1]![Combo4] = "Available", True, False)
Note I assumed you want True when the combo's value is "Available" and False for anything else. If the possibilities are more complex, you could use a Switch expression to assign the correct Boolean for each possible combo value ... or use a lookup table which maps between the two.

If then record selection with multiple conditions

Using Crystal Reports 2011 to reference a View
My formula written as a "formula field"
#mySelection
IF {V_JOB.TASK} LIKE "*IN"
AND {V_JOB.CLOSED} = "Y"
AND {V_JOB.DATE} >= {?FrDate}
AND {V_JOB.DATE} <= {?ToDate}
THEN {V_JOB.JOB} ELSE "FALSE"
My record selection written in the "Record Selection Formula"
{V_JOB.LMO} = 'L' AND
{#mySelection}
This View contains several relevant fields. To make my record selection of the view, I want to display all records that are equal to string in .JOB, when string in .TASK like "*IN" and field .DATE = ?myDateRange and field .CLOSED = 'Y'
so I wrote the equation to do exactly that, but the displayed records are row JOB only when TASK,DATE,CLOSED are true. But I have multiple rows of the same JOB where TASK,DATE,CLOSED is false that I also want to see.
So if there are 30 records for Job A and only 1 of those records has #mySelection is "true" then I want to select ALL 30 records even if the other 29 are "false". The way it is written it only displays the 1 true record and not the other 29.
Can anyone provide some assistance on what I'm doing wrong? Is there a "show all" command or perhaps I can save "true" JOBs in an array and then reference the array as my record selection?
Where abouts are you inputting your formula within crystal? It is very important.
You should be able to achieve what you want by using conditional suppression in the details section of your report. Something like this...
//Untested//
IF {V_JOB.TASK} LIKE "*IN"
AND {V_JOB.CLOSED} = "Y"
AND {V_JOB.DATE} >= {?FrDate}
AND {V_JOB.DATE} <= {?ToDate}
THEN False ELSE True
This will suppress results where they do not equate to the above conditions.
I found your question a little unclear so this answer might not be perfect for your needs, but hopefully it's a shove in the right direction.
I was able to accomplish this using a sub-report to record select with a parameter reference from the main report
{V_JOB.LMO} = 'L' and
{V_JOB.JOB} = {?Pm-V_JOB_OPERATIONS.JOB}
Then I created a main report and linking a parameter to Job.Job in the sub report and did a record selection for my criteria in the main report.
{V_JOB.TASK} LIKE "*IN"
{V_JOB.CLOSED} = "Y"
{V_JOB.DATE} >= {?FrDate}
{V_JOB.DATE} <= {?ToDate}
I then put the sub-report in the details section but that created a duplicate record issue if there was more than one record for Job.Job that satisfied my selection. So to fix that I created a group for Job.Job, and put the sub-report in the group header and suppressed the detail.
I'm not sure this is the most efficient use of CPU power or the best way to program this in CR, but it gives me the correct results that I need, and relatively quickly for the size of the database.
Your Record Selection forumula should be something like this.
{V_JOB.LMO} = 'L' AND
{V_JOB.JOB}
Now you have all the records in your CR.
Use the below formula as a supression option for the field where you are displaying records.
#Supress
IF {V_JOB.TASK} LIKE "*IN"
AND {V_JOB.CLOSED} = "Y"
AND {V_JOB.DATE} >= {?FrDate}
AND {V_JOB.DATE} <= {?ToDate}
THEN true ELSE false
If your condition is true then all records will be displayed else all records will be supressed.
I would suggest you to not to apply these type of conditions in Record selection formula.