Need to auto-populate form fields based on another field on the same form

stlryan82

New member
Local time
Today, 10:12
Joined
May 31, 2011
Messages
8
Hello everyone,

I'm fairly new to Access and I've been racking my brain over this particular issue for a couple of days now, and I was wondering if I could perhaps get some assistance.

I have a form (that is sourced to a query) that has 5 date fields. I want to be able to enter a date in Field1, and I want the other 4 fields to auto-populate as follows:

Field2 = Field1 + 1 year
Field3 = Field1 + 2 years
etc, etc

I've tried using the DateAdd function in the Default Value of each Date Field in the Form itself with no luck. I also tried using that same function as a VB code in AfterUpdate Event, but no luck again.

Any suggestions would be greatly appreciated.

Thank you,
Ryan
 
I'm sure there are better methods, and we don't know for sure what you really need. But to answer your question, I think this will work.

Form is unbounded; 5 text fields; put date in the first one; the others have a value 1,2,3,4 years greater than entered date.


Private Sub TextField1_AfterUpdate()
Me.TextField2 = Format(DateAdd("YYYY", 1, CDate(Me.TextField1)), "mm/dd/yyyy")
Me.TextField3 = Format(DateAdd("YYYY", 2, CDate(Me.TextField1)), "mm/dd/yyyy")
Me.TextField4 = Format(DateAdd("YYYY", 3, CDate(Me.TextField1)), "mm/dd/yyyy")
Me.TextField5 = Format(DateAdd("YYYY", 4, CDate(Me.TextField1)), "mm/dd/yyyy")
End Sub
 

Users who are viewing this thread

Back
Top Bottom