MS Access calculated fields changing to "#Error" - forms

I currently have a form that runs off of a query and everything works swimmingly, or at least it appears. I have three fields in question: an ID field, a Client Name field, and an Age field. The age field is actually the client's age at the signing of the quote, so it is a calculated field using the date of the quote and the client's DOB.
The age calculation works perfectly upon first look. The reason the ID and name fields are in question are because when I double click them it opens a form, which yet again works fine. The problem is when I exit those forms and come back to the original form.
The age field of whatever record I was on changes to "#Error" instead of what it was displaying. If i click on a different record in the form then that age field changes to "#Error" as well. This seems to happen every time and I have no clue why.
Has anyone solved an issue similar to this or have an idea on how to solve it?
Thanks in advance!
Update: I changed it to open a report rather than a Form and the issue is still there.
The calculation in question: Int(([effectiveDate]-[dateOfBirth])/365.25)

Try calculating age this way:
DateDiff("yyyy", [dateOfBirth], [effectiveDate]) + ([effectiveDate] < DateSerial(Year([effectiveDate]), Month([dateOfBirth]), Day([dateOfBirth])))
Using this method takes the difference in years between your date of birth and the effective date, taking into account that the person's birthday may not have passed yet by that date.
Basically the first part gets the years and the second part either adds 0 for false or adds -1 for true if the effective date is LESS than the birthday for the effective year (meaning it hadn't passed yet)

Related

how to use datediff properly tableau

basically i have the same problem with this and use this solution too https://community.tableau.com/s/question/0D54T00000C6aS6/datediff-in-lod
so i want to count time diff between transaction for each transaction and for each users, basically my problem is just like this
same with that, ON interaction id = user id in my real data, so i want to know time different between date transaction for each users.
based on that, i made this on calculation DATEDIFF('day',LOOKUP(MIN([Created At]),-1), MIN([Created At]))
and here's the results
what makes me confuse is, why the first transaction of users always have time difference, instead it must be nothing because there's no time difference if you do first transaction, so how to make it not appear?
Create a table calc field for First
FIRST()=0
Edit the table calc so it resets ever new user id.
Now filter for False. You can remove it from Rows, I just kept it there for demo. Your calculation will still work.

How to stop date when someone dies

I have an access database for my dairy farm. I have one field named DateBorn, a module function fAge, and an unbound field named AgeNow. For this I have the expression:
=IIf(IsNull([DateBorn]),"",fAge([DateBorn]),Date()))
With this expression, whenever I type in a value for DateBorn, it calculates age for me in years, months, and days. It has worked fine thus far.
Now I want to add something to it; another field named DateDied. I want an expression that whenever I put DateDied, it should stop calculating age for that particular record.
I'm not sure if you made a mistake in your sample regarding calling the function fAge().
I expect it needs two date parameters.
That expression always calculates the age, but for people who died it uses DateDied instead of Date():
=IIf(IsNull([DateBorn]),"",fAge([DateBorn],NZ([DateDied],Date())))
If in case of dead people there shouldn't be any calculated age use this:
=IIf(IsNull([DateBorn]) Or Not IsNull([DateDied]),"",fAge([DateBorn],Date()))

How can I use Crystal Reports record selection to choose from a list AND included a specific field

I am trying to figure out how to write a formula in the record selector that would allow me to select records in a specified list....but ONLY if there is also a specific record.
In My example. I am pulling earnings codes for employees from specific payroll transactions. For each Transaction date...each employee will have up to 10 codes.
I have my record selection set as this to narrow down the codes I want to see:
{UPCHKD.EARNDED} in ["01", "02", "BNSQT", "BVMT", "CASHBO", "FLAT", "HOL", "HOLPAY", "WAPFML"]
The issue is that I only want to see the first 8 codes IF there is also the WAPFML code. I can't figure out how to tell the record Selector to pick records that have BOTH WAPFML and any of those other 8 codes.
{UPCHKD.EARNDED} in ["01", "02","BNSQT", "BVMT", "CASHBO", "FLAT", "HOL", "HOLPAY", "WAPFML"] and
{UPCHKH.TRANSDATE} in {?Beginning Check Date} to {?Ending Check Date}
I hoped to see only checks where the WAPFML code existed. But I'm obviously returning checks that may not have that code. Using Group selection doesn't work as then I don't see the lines for the other codes.
Assuming you are grouping on {Employee_ID}, Add a group selection formula of MAX({UPCHKD.EARNDED}, {Employee_ID} ) = "WAPFML"
This takes advantage of the fact that "WAPFML" happens to be the largest alpha value in the set. If that is not the case, a more robust approach is to add the UPCHKD table a second time (with an alias), join on same Emp_ID to the first alias, and add a record selection condition on the 2nd alias forcing it to be "WAPFML"
OH I GOT IT! I was grouping by Employee and then transaction date. I entered Maximum ({UPCHKD.EARNDED}, {UPCHKH.TRANSDATE}) = "WAPFML" and took maximum of each transaction date and BOOM. Which now makes all the sense in the world. Thanks so much MilletSoftware for helping me!

How to reuse data in multiple records in Access form

Big question: How can I make Access automatically fill in a cell in a form based on previously entered data?
I need to enter leave details for members of staff. I tend to enter these by date, and in one to two week chunks. Is there a way to have the next new record automatically fill in the date part of the record with the previously entered one?
Table structure
Staff: StaffID, Name
Absences: ID, StaffID, Dateaway, OtherDetails
I want it to automatically fill in DateAway with the entry of the row above it, or the previously entered row, as I will enter say 10 dates in a fortnight, but 50 entries over those dates. I enter them chronologically, and after the fact (So just defaulting to TODAY() won't work).
There's a shortcut Ctrl+' that does pretty much what I need, wondering if there's a way to do that with the generation of a new record.
You have to be careful with this. If your form is bound to a table/query, you're going to insert a junk record every time you're done with the form. However, if it's unbound you can do this using DMAX, in the After Insert event of the form.
Private Sub Form_AfterInsert()
txtDateaway.Text = DMax("Dateaway", "Absences", "StaffID = " & Me.txtStaffID)
End Sub
This is, of course, assuming your Dateaway field on your form is called txtDateaway and your StaffID field is called txtStaffID.

Get minutes from a time field in a CakePHP form?

I'm using CakePHP to build a mixed martial arts (MMA) website. I have a form to add matches, and one of the fields is for rounds length, which is in minutes, and which I'm storing in my database as a TIME value.
In my form, I only want the minutes portion of the value editable. I've tried creating a field with the name Match.rounds_length and setting the type to number, but can't get it to populate with the minutes value.
Here's what I have currently:
$this->Form->input('Match.rounds_length' => array('type' => 'time'));
I did find this page in the CakePHP online documentation: http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#field-naming-conventions. But I can't seem to get it to work in my setup.
Could someone familiar with CakePHP tell me how to create just an open text field that the user can specify the number of minutes a round should last that would then be saved as a time value in my database, and populated properly in my edit form?
I tried the following. And it worked.
echo date('i', strtotime('00:05:00'));
date() format specifiers list will help you to achieve the same as you mentioned in your question.
Kindly ask if it not worked for you.