Hope you're doing well. I have a question in Access. I have an Employee Table with some Fields and 2 of them are 'EndofContract' and the other is 'Condition'.
The EndofContract field is in date format (is the date in which the employee stopped working in the company) and what I want do to is autofill the Condition field with Inactive or Active, based on the date of EndofContract. Basically:
if EndOfContract is blank I want to show Active in Condition;
if EndOfContract has a date that is previous to today's date, I want to show Inactive in Condition
I've tried various different things and the last one was going to Design View » Condition Field » Lookup » RowSource and in the query designer I wrote this condition IIf(Date()>[EndofContract];"Inactive";"Active") but it doesn't work. Already tried an AfterUpdate macro but I can't understand how to change the value of every record.
Hope somebody can help me and thank you!
Have a textbox on your form where you display the data.
Assign this expression as its ControlSource:
=IIf(Nz([EndofContract],Date())>=Date(),"Active","Inactive")
or, if semicolon is your list separator:
=IIf(Nz([EndofContract];Date())>=Date();"Active";"Inactive")
Or, remove the field Condition from the table and use a query:
Select
*, IIf(Nz([EndofContract],Date())>=Date(),"Active","Inactive") As Condition
From
EmployeeTable
If EndofContract is text, not a true DateTime value, try this:
Select
*, IIf(Nz(CVDate([EndofContract]),Date())>=Date(),"Active","Inactive") As Condition
From
EmployeeTable
This requires no updates.
Related
Pic hereI am new to MS Access. I have a customer table with creationdate field as well as submissiondate. The submissiondate was calculated via a query since it carries multiple conditions. I created a form from the customer table where I am able to input the creationdate field and I managed to show the submissiondate (from the query) via Dlookup but the date is not recorded in the customer table. How can I record the submissiondate value from the query in the customer table without having to do an update query every time I add a new customer? I did an update query but it updates all records every time it runs, and we have more than 50K customers. Any help is appreciated.
this is the query in Access that gets the result for me.
SELECT HardDeadlineCalculationQ1.ID, HardDeadlineCalculationQ1.R AS ReferralDate, HardDeadlineCalculationQ1.[Source of Referral], HardDeadlineCalculationQ1.HD1, HardDeadlineCalculationQ1.wdhd1, HardDeadlineCalculationQ1.hd2, HardDeadlineCalculationQ1.wdhd2, HolidaysT.holidaydates, Switch([HardDeadlineCalculationQ1].hd2=holidayst.holidaydates,"Yes") AS isholiday, IIf(isholiday="Yes",([HardDeadlineCalculationQ1.hd2]-1),[HardDeadlineCalculationQ1].hd2) AS hd3, WeekdayName(Weekday(hd3)) AS wdhd3, Switch(WeekdayName(Weekday(hd3))="Monday",(hd3),WeekdayName(Weekday(hd3))="Tuesday",(hd3),WeekdayName(Weekday(hd3))="Wednesday",(hd3),WeekdayName(Weekday(hd3))="Thursday",(hd3),WeekdayName(Weekday(hd3))="Friday",(hd3),WeekdayName(Weekday(hd3))="Sunday",(hd3-2)) AS hd4, WeekdayName(Weekday(hd4)) AS wdhd4
FROM HardDeadlineCalculationQ1 LEFT JOIN HolidaysT ON HardDeadlineCalculationQ1.hd2 = HolidaysT.holidaydates;
regards,
"The submissiondate was calculated via a query since it carries multiple conditions"
By this, i presume you mean that the submission date is a calculated field(as its control source)
Do the following
Copy the calculation, i.e formula and put in vba code, under the after update event of every field that is a variable in the expression.
e.g submissiondate= place the formular here
Then on the form remove the calculation , i.e formula from the control source of the form control and make a field in the table the control source, e.g submissiondate.
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
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.
I have a form based on a table.
I have a purchase_date field and an expiry_date field.
I want expiry_date to add 6 months to purchase_date (in my form) and then insert this value into the table.
I have created this expression: DateAdd("m",6,[purchase_date]) as the control source of expiry_date. This works as expected but this value is not being updated/ saved from the form into the table. I have tried using onClick and afterUpdate functions to run the expression but no joy.
Thanks for any help.
Have you tried OnSave? Your dateadd syntax seems ok. Watch out for any protected cells/sheets! You can generally use activesheet.unprotect if this is the case.
Also, activesheet.calculate might help you, if correctly placed in your VBA.
I have an SSRS report
where the date should be grouped by project category
the project code in the category is repeating in side the group how do I suppress the value
Please help me to get an idea.
Thanks,brijit
You can also hide fields by putting an expression in the Hidden property like this:
=Fields!ProductCode.Value = Previous(Fields!ProductCode.Value)
So if the value in the previous record is the same as this one, it will hide the field. You must sort the dataset correctly for this to work. In your case I think the sorting would be Date, ProductCategory, ProductCode.
In the past I used this often together with expressions for field borders to group the output visually.
I think there is one option hide duplicates in properties in ssrs. so you will check in that option under the project category group.so that you can hide the duplicate values and get unique records. first u create one group based on project category in fields properties and then check in that hide duplicate option under that group.whenever you check in that option it will high light one drop down list showing containing group or dataset there you select your created group.
This is a bit late for you brijt, but what I do is edit the textbox properties for that field, in the font tab enter an expression for Color as follows:
=IIf(Fields!ProductCode.Value = Previous(Fields!ProductCode.Value), "White", "Black")
...assuming your background is white this will effectively do what you want.
I think it may be an issue concerning the way you are grouping the dates. Do you have the grouped with time on them as well but suppressing the hours in your output?
For example:
12-5-2010 12:00:00
12-5-2010 13:00:00
if you strip the times off in how you see them but not how you group them, they would show up duped.