Microsoft Access - query checkbox based on textbox - ms-access

I have a field text field containing dates.
I also have a checkbox named "Delivered"
If the text field contains a date, I would like the "Delivered" checkbox value to be "True" / ticked.
If the text field isNull, the checkbox value must be "false" / not ticked
I have tried the following in the query expression builder of my checkbox:
IIf([DateField]="";False;True)
but I keep getting an error about the expression being built incorrectly?

You are trying to store a Calculation/dependent value in a table based on a field in the same table, this is not advisable and should not be carried forward. Calculations should be done when and where required, like display on Forms, Query to export or Reports to show. More info on Calculation field is available here : http://allenbrowne.com/casu-14.html
If you really want to then you can create an UPDATE Query as,
UPDATE
tableName
SET
DeliveredFieldName = IIF(Len(DateFieldName & '') = 0, False, True);

Related

Brining row where column valus is null

I have a store procedure which brings the data as shown below . I'm new to SSRS reporting, I would like to show only those row where "email" column is null. How can i achieve it in SSRS ? As i mentioned I'm very new to this , any screenshot will help me a lot. Thank you for your time.
For this problem, you'll want to change the row visibility to hide rows with a value in that column. I assume you're using a table or matrix to layout this data. You'll want to right click on the row where your data fields are entered. Specifically, the grey box at the left of the row.
From there, you'll need to select the option to Show or hide based on an expression.
And finally, you'll need to enter an expression that finds the values in the email field. I'm not exactly sure what the field names are called but something like the following expression should do it.
= Not IsNothing(Fields!EmailField.Value)
This will check the field where you get the email value with a built-in function of IsNothing. Additionally, since you want fields that do not contain values, the Not keyword reverses the results. If the function evaluates to true and a value is present, the row will be hidden and vice versa.

MS Access, Use Expression Builder to Compare Field in One Table to DLookup in Another Table

I'm trying to make a MS Access report, where I use a text box to display a field value, then have another text box indicating if the first value is higher or lower than an entry in a separate table.
The report has a record source of "Table 1", and a textbox named "txt_Value1" which displays the number in Field: "Value1". I have a second table, "Customer_Criteria" which has a field "PassValue" that I want to compare against. My expression builder statement is:
IIf([txt_Value1]<(DLookUp("[PassValue]","[Customer_Criteria]","[Customer] = 'ABC'")),"TRUE","FALSE")
This statement always returns false, regardless of what the correct logical result is.
I've tested it, writing:
IIf(1<(DLookUp("[PassValue]","[Customer_Criteria]","[Customer] = 'ABC'")),"TRUE","FALSE")
And I get the correct results. Also, if I write:
IIf([txt_Value1]< 1,"TRUE","FALSE")
I get the correct results. What am I missing to compare the textbox value vs. the Dlookup?
As I understand, both fields are numeric. Access may consider those fields as text, so for correct comparing use type conversion.
Try this:
IIf(CLng(Nz([txt_Value1],0))< _
CLng(Nz(DLookUp("[PassValue]","[Customer_Criteria]","[Customer] = 'ABC'"),0)), _
"TRUE","FALSE")
Nz required if fields may contain NULL values, in this case type conversion function will return error.

Adding an Expression to a MS Access table

I need to add a "STATUS" field to an Access table... Creating the field is the easy part.
I need to display one of three words based on a date from another field.
So in the "Status" field I need to take the date and if it less that 180 days from the date field have the "Status" field display "CURRENT"
If the date is between 181 days and 365 days I need it to display "SUSPENDED" and over 365 days I need it to display "EXPIRED".
If it is also possible to have the field show color based on the current, suspended, expired output that would be a bonus.
I find using calculated columns in tables can be cumbersome and you are limited to what you can do. I would recommend creating a query on your table instead and add the following expression to a new query field:
Status: IIf(DateDiff("d",[YourDateField], Date())<=180,"CURRENT",IIf(DateDiff("d",[YourDateField], Date())>=181 And DateDiff("d",[YourDateField],Date())<365,"SUSPENDED","EXPIRED"))
Make sure to test this a let me know if the calculation is right for each scenario. I may have it backwards.
As far as formatting the field based on the status, this can be accomplished with a textbox in a form or a report. If you select the "Status" textbox in the form/report's design view and then in the ribbon go to the "Format" tab in the "Form/Report Design Tools" menu, click on "Conditional Formatting". There you can specify rules to the textbox background color based on what the status value is.
Hope this helps!
On the form where you are presenting your data you can create a calculated value in a textbox. You can use Conditional Formatting to change the color (in datasheet view) or VBA (in Form view)
Alternatively if you are using a query to present your data on your form you can add another table with these threshold dates and join to it. Then your dates can be dynamic and not hardcoded into your forms.
Use a Switch() expression in a query to derive "Status".
Here it is formatted with each condition/value pair on a separate line. Similar to a VBA Select Case ... End Select block, Switch() returns the value from the first condition which evaluates as True, and ignores the rest.
Switch
(
DateDiff('d', [YourDateField], Date()) < 181, 'CURRENT',
DateDiff('d', [YourDateField], Date()) BETWEEN 181 AND 365, 'SUSPENDED',
DateDiff('d', [YourDateField], Date()) > 365, 'EXPIRED',
True, Null
)
The last condition catches any YourDateField value (eg Null) which doesn't satisfy one of the first three conditions.

Using optional multi-value textbox as dataset filter

I have a report which returns list of product names and other product specs. This report currently has different search options. My users now also want to be able to search by product number by putting in multiple product numbers.
How can I add a filter by product number which is an optional multi-value textbox?
I have tried to add a multi-value textbox. The report doesn't seem to work when no values are entered. If I put one or more product number in the text box, it seems to work fine. Is there a way I can tell the report doesn't filter on the Null value parameters? Or any other idea to work with optional multi-value parameters?
Here is the setting for my multi-value textbox
Name = ProductNumber
Prompt = Product Number
Data Type = Text
Allow Blank Value (checked)
Allow Null value (not checked)
Allow Multiple Values (checked)
Here is the data set filter
Expression = [ProductNumber]
Operator = In
Value = [#ProductNumber]
Thanks
TL
I think you should trick the dataset filter by:
Expression should check to see if the parameter is blank and if so give expression a 1 else the field.
Value should do the same check and if parameter is blank set value to 1 else set it to the parameter.
But keep your operator.
Alternatively you could do this similarly in the SQL and with more flexibility and performance.
So as you've seen in your own testing, at least one value must be selected with multi-value parameters. You can't set Allow null value to true at design time and if you run a report without selecting any values it will throw an error message.
So you can't really have a report where users can run it with no values selected.
Taking a step back, what you're trying to achieve when ignoring the parameter is to include all Product Numbers by default. So why don't you set the parameter to have a default value of all Product Numbers selected? That way, users can just ignore and leave them all ticked if they don't want to filter by Product Numbers. Seems like a good workaround to me.
To do this, set the default value for the parameter using the same dataset that populates it:
All Product Numbers are now selected and users only need to take action if they want a subset of these returned.

access 2010 expression builder

I want a text box to contain data which is a calculation based on 2 other control field values - only if it's value is null (ie the current value of the column in the database is null).
So I entered =([control1]*[Control2])/1000 in the expression builder for the default value property - however the result always shows the textbox to be empty (even tho control2 and control2 contain values).
How can I achieve this? Can such an operation only be done in code-behind ie VB??
thanks,
KS
I think you're talking about a control bound to a field in the form's record source. And when the underlying field is Null, you want the control loaded with your calculated value.
If that interpretation is correct, you can do it from the form's On Current event.
If IsNull(Me.txtYourTextBox) Then
Me.txtYourTextBox = (Nz(Me.control1) * Nz(Me.Control2)) / 1000
End If
That will load the computed value into the text box, allow the user to change its value if desired, and store the value to the bound field when the record is saved.
If the bound field is not Null, its value will be displayed in the text box without alteration by the On Current code.
Is that what you want?
To accomplish this using VBA, add a Form_Load Event. (Open the form in Design View and in Form properties click the Event tab and choose Event Procedure for "On Load" and click ...)
This example uses [TextField] to refer to the table data.
Private Sub Form_Load()
TextControl.SetFocus
If IsNull([TextField]) Then
TextControl.Text = ([Control1] * [Control2]) / 1000
End If
End Sub