I have a question about using an IIF statement with a Yes/No field. In my case, I am trying to get the statement do one thing if the Yes/No field=Yes and another if it is "No." I realize Access stores the Yes/No field as -1,0 and have attempted to formulate the statement this way.
I did make this statement:
NetDonation: IIf([PickupRequired]-1,[DonationValue]-8.75, 0, [DonationValue])
Unfortunately, this statement does not differentiate between the PickupRequired field being "No" or "Yes" and it subtracts 8.75 from all values regardless if the PickupRequired field = No.
IIf() will recognize Yes/No fields as True or False without your having to specify a numeric value, so the following will work just fine
IIf([PickupRequired], "The value is Yes", "The value is No")
In your particular case I suspect that you want
NetDonation: [DonationValue] - IIf([PickupRequired], 8.75, 0)
Related
I was wondering if you can make an if statement in Microsoft Access.
The idea is you have 2 columns. 1st one is called "Quantity" (type is number) and 2nd one is called "In stock" (type Yes/No) and want to make the statement:
"if quantity > 0 then "In stock" should be tick otherwise no tick."
I was trying:
iff([quantity] = 0, [in stock] = "No", [in stock] = "Yes")
also tried this
iff([quantity] = 0, [in stock] = false, [in stock] = true)
Hopefully you get it, can someone help or tell me if its possible to make this?
Thanks in advance
If you are using a version of MS Access which offers the Calculated field type, this task is relatively simple and does not require queries or code.
Simply configure your In Stock field to be a Calculated field, calculated using the expression:
[Quantity] > 0
Set the Result Type to Yes/No to indicate that the result will be that of a Boolean field.
The Format may be set as appropriate for your application (Yes/No I would assume).
all editions of Microsoft Access support calculated values in queries. It is a matter of implementing it correctly. i.e.:
In Stock: iff([quantity] = 0, "No", "Yes")
This is put in and creates the new field: In Stock
Firstly, you can't use the IIf function to change the value of a checkbox or a bound control.
If what you want to do is simply determine which item/product is in stock and which isn't, you don't actually need have any field such as the [In Stock] field to be in the table. A more elegant method is to simply evaluate the Quantity field and use an unbound text box to display Yes or No.
Set the unbound textbox's control source to:
=IIf([Quantity] > 0, "In Stock", "Out of Stock")
A slight alternative is:
=IIf([Quantity] > 0, "Yes", "No")
In the case of the slight alternative above, you change the label or header label of the unbound textbox to "In Stock". This way, the Yes or No that will be displayed for each product will make sense to all users and viewers. Please note that the equal sign (=) is part of what you will type.
If for some reason you need to store the [In Stock] field as as a Yes/No data type in the underlying table and you want to update this value to Yes or No (tick or untick), then you could use a macro. In this macro, you would use the traditional If Then Else statement together with the SetValue action. I can't post screenshots/illustrations at the moment because I am currently using a phone. The statement will be as follows:
If [Quantity] > 0
Then SetValue [In Stock] =Yes
Else: SetValue [In Stock] = No
NOTE: you could also subtitle 1 for Yes and 0 for No.
I am trying to write an Access query (Access 2013) that uses an IIF statement to first check the value of an Option Frame and then, if the value is "1", use a date range or, if the value is anything else, find all records (only values "1" and "2" are available). My query criteria is...
Like IIf([Forms]![MaintenanceDueList]![OptionFrame]=1,>[Forms]![MaintenanceDueList]![FromDateText] And <[Forms]![MaintenanceDueList]![ToDateText],"*")
When my Option Frame Value is set to "2" I get all records returned as expected, but when my Option Frame value is set to "1" I get no results at all, despite there being plenty of records available with dates between the two dates provided in the FromDateText and ToDateText TextBox fields.
This one really has ne stumped, so any help would be gratefully received. Thanks, Mort640.
IIF returns a value but you seem to be trying to return some SQL logic - the true/false parts are evaluated then returned.
You can instead:
WHERE
[Forms]![MaintenanceDueList]![OptionFrame] = 2
OR
XXX > [Forms]![MaintenanceDueList]![FromDateText] And XXX < [Forms]![MaintenanceDueList]![ToDateText]
or to be inclusive of XXX as opposed to greater-than
WHERE
[Forms]![MaintenanceDueList]![OptionFrame] = 2
OR
XXX BETWEEN [Forms]![MaintenanceDueList]![FromDateText] And [Forms]![MaintenanceDueList]![ToDateText]
The field is taken from the table and is the source of data for the textbox, in which I want to apply conditional formatting. Almost always it is NULL. The expression for the conditional formatting:
Not IsNull ([duedate])
Always returns true, I do not understand why. Field [duedate] belongs to the parent form.
I think you need to check the length also along with IsNull like
Len(Field) = 0
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.
I am working with SSRS and have a tablix that needs certain rows excluded if a value in a multi-value parameter is not selected. For example, the multi-value parameter is 'Include Loss' and the values are 'Yes' and 'No'.
So if the user selects 'No', then I want the tablix to exclude rows where Description field is equal to the text "Loss Transaction".
I am trying to write an expression to filter on the tablix as follows, but having no luck.
=IIF(Parameters!IncludeLoss.Value="N", Fields!Description.Value, NOTHING)
and use '<>' for the 'Operator' and then:
="Loss Transaction"
I get the error 'Failed to evaluate the FilterValue of the Tablix'. Any suggestions? Thanks in advance!
Filters have an implicit AND relationship - that is, all the conditions have to be True for the filter to take effect.
Accordingly, you can have two filter conditions set:
=Parameters!IncludeLoss.Value is equal to N (add a second condition)
=Fields!Description.Value is equal to ="Loss Transaction"
Alternatively, for complex conditions (or conditions involving OR or Null which aren't supported in a standard filter) you can just use one condition and set that condition's expression to something more complex that evaluates to a boolean and test that against True. For example:
=Parameters!IncludeLoss.Value = "N" AND Fields!Description.Value = "Loss Transaction"