Full Version: Date Field Default To One Year But Can Be Edited
UtterAccess Forums > Microsoft® Access > Access Forms
dmkeith2
Hello,
would like a date field to default to one year after another field that is on the form. I tried this in the default box, but it didn't do anything. The field needs to be able to be changed in case the user would like to.
DateAdd("yyyy",1,[Last_Thru])
Thanks for the help.
theDBguy
Hi,
would recommend using the AfterUpdate event of [Last_Thru] textbox. For example:
Me.FieldName = Nz(Me.FieldName, DateAdd("yyyy", 1, Me.Last_Thru))
Hope that helps...
dmkeith2
Sounds like a winner, I'll try that. Thanks.
theDBguy
Hi,
Good luck and let us know how it goes...
dmkeith2
Hello,
This is what I entered in the After Update event for Last_Thru you'll notice the system defaulted and added the additional brackets.
=[Me].[Next_Due]=Nz([Me].[Next_Due],DateAdd("yyyy",1,[Me].[Last_Thru]))
I'm getting this error:
The object doesn't contain the Automation object Me.
I've tried other variations with no luck, removing Me, etc.
Thanks.
theDBguy
Hi,
You may have missed some steps...
1. In the AfterUpdate event, click on the dropdown arrow and select [Event Procedure]
2. Click on the three dots (...) to the right of [Event Procedure]
3. In the code window that opens up, type the following:
Me.Next_Due.DefaultValue = DateAdd("yyyy",1,Me.Last_Thru)
Note: I changed the code after re-reading your original post.
Hope that helps...
dmkeith2
Thanks, I tried to add it directly to the afterupdate field instead of as an event procedure. That fixed it.
theDBguy
Hi,
Glad to hear you got it to work. Good luck with your project.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.