Link to home
Start Free TrialLog in
Avatar of Frank Vertin
Frank Vertin

asked on

MSAccess2013, Multi-Tabbed Form, Current_DATE. Can someone help with this problem?

I have a Tabbed Form with 8 Tabs I added a text field to the base Form, then added the first name + " " + the last name from the  first Tab. The name is shown no matter which Tab that your on and I buttons if you use the block of navigation buttons at the bottom of each tab and move up or down the records the name follows in sync with the records. Now, the problem is I carry dates in the database, (i.e. Birthdays, Wedding dates, or Children's Birthdays). My attempt is to hold the current date on the form base to use  in date math so that I can calculate the age of the members.  Since these things change as the days pass, I can make it let me know when and who to direct my attention to.

I can do it in MS-EXCEL, but MS-ACCESS is giving me fits.
Avatar of Bitsqueezer
Bitsqueezer
Flag of Germany image

Hi,

you described that you have problems with this, but you didn't show your tries and what's the error in Access. Maybe you should start to show your solution in Excel and then what you've tried in Access so it's easier to follow you.

If you want to calculate with dates there are VBA functions you can use like DateAdd or Year.
You should also keep in mind that Access can use a "not defined" value called NULL (not the number 0) especially mostly used in case of dates when the user leaves the field empty. As NULL means "not defined" any calculation with NULL results again in NULL so if you would try to calculate "1 + NULL" the result is again NULL. If you add an expression in a field on an Access form this would result in an empty field.
You can use a replacement value using the function "Nz" (Not Zero, better would be it would be named as NN for Not NULL). Nz allows you to use a replacement value if a field is NULL. But in case of dates it mostly makes no sense - what date should you use as replacement if the user didn't enter a birth date? So here it's better to use an expression which also leaves the calculated field empty, like "=Year(Now())-Year([BirthdayDateField])".

If you try to calculate that in VBA it may result in an error (depending on your method), so here you may need to check first if the date field you want to use is NULL. (There is a "IsNull" function to do that.)

But to be more detailed you must describe in detail what you tried and what was the result (show the code or expression and the exact error messages).

Cheers,

Christian
I see two issues.

1. Display the current date.
I assume you have this handled with an unbound control, the value set to =Date().  
The function is not Today()

2. Calculate from the current date. This can be confusing in Access since you need to refer to the form data control. Don't get distracted. The value in the form control will be date(), so use that value in your calculations.

I hope this helps you over your issue.
if you use the block of navigation buttons at the bottom of each tab
Tab pages don't have distinct Navigation Buttons. You must be referring to a Form's Navigation Buttons.

Are you using Subforms? If so, then each of the Subforms could have a set of Navigation buttons as well, and referring to data/values between a Mainform and a Subform (or between different Subforms) can be troublesome as well.

As the others have said, you need to provide more detail as to exactly what sort of issue you're having. If possible, show screenshots and indicate where the trouble is, or upload a copy of the database here (be sure to remove or obfuscate any sensitive information, of course). If you do provide a copy of the db, be sure to let us know exactly how to recreate your issue.
When you calculate ages
To make my suggestion clearer, I am recommending to use the Date() function when calculating the ages and to not try to use the value on the form..
Avatar of Frank Vertin
Frank Vertin

ASKER

I need some clarification  on this, I appreciate your effort. Can you help me understand?
ASKER CERTIFIED SOLUTION
Avatar of Richard Daneke
Richard Daneke
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This looks like the best idea I've seen, yet.  Everybody came up with different versions of sticking =Date() in a text field or property field of that text field just gave me a compiler error. I will try yours and let you know.
Hi Richard,

Just a little clarification, where do you suggest I put this code? I've done code that affects Excel, but  Access is foreign  to me as far as doing something with record macro, then looking at the code and working it out. I don't get that comfort level with Access.

Thanks, Frank
Frank,
You can place the code above in the AfterUpdate of your age field in a form where Birthdate is the name of the field on which you want to calculate the age in years.
You did it in a smart way, Richard.