Date Fields

CanWest

Registered User.
Local time
Today, 11:16
Joined
Sep 15, 2006
Messages
272
I have four date fields in a form. They are most likely all going to be the same date, however there is the possibility of them being different. I would like feild 2, 3 and 4 to automatically take the value of feild 1.

I hvae tried


Code:
    Forms!pfrm_EventAdd!ScheduledEndDate = Forms!pfrm_EventAdd!ScheduledStartDate
    Forms!pfrm_EventAdd!ActualEndDate = Forms!pfrm_EventAdd!ScheduledStartDate
    Forms!pfrm_EventAdd!ActualStartDate = Forms!pfrm_EventAdd!ScheduledStartDate

on the afterupdate, onexit and onchange properties

The only one that sort of works is the onexit which does set the valuse but the are not visible until the next time you open the form
 
Please show the After Update event code.
 
Please show the After Update event code.

Code:
Private Sub ProgramAddScheduledStartDate_AfterUpdate()

    Forms!pfrm_EventAdd!ScheduledEndDate = Forms!pfrm_EventAdd!ScheduledStartDate
    Forms!pfrm_EventAdd!ActualEndDate = Forms!pfrm_EventAdd!ScheduledStartDate
    Forms!pfrm_EventAdd!ActualStartDate = Forms!pfrm_EventAdd!ScheduledStartDate
    

End Sub
 
Here's an example of a form with 5 text fields

TextField1 thru TextField5. After a Date has been entered into txtField1, the other txtFields are filled with the same Month and Day, but are 1,2,3 and 4 years hence.


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


good luck.
 
Here's an example of a form with 5 text fields

TextField1 thru TextField5. After a Date has been entered into txtField1, the other txtFields are filled with the same Month and Day, but are 1,2,3 and 4 years hence.
good luck.

Ok not sure why they are 1,2,3 and 4 years hence. I need them all to be the same date.
 
Well the example was to show a concept - How to use an AfterUpdate event of text box1 to set the values in other text boxes (after the first text box value was updated).. You can adjust the code any way you like. Make all the values the same-- any expression you want.
 
When referring to a Control on a Form in its Code Module you don't need to fully reference the Form, simply use Me.ControlName.

So, for your code
Code:
Private Sub ScheduledStartDate _AfterUpdate()
   Me.ScheduledEndDate = Me.ScheduledStartDate
   Me.ActualEndDate = Me.ScheduledStartDate
   Me.ActualStartDate = Me.ScheduledStartDate
End Sub
This will populate all Date Fields with the same date, but allow you to manually change any or all of them, if necessary.

Linq ;0)>
 
When referring to a Control on a Form in its Code Module you don't need to fully reference the Form, simply use Me.ControlName.

So, for your code
Code:
Private Sub ScheduledStartDate _AfterUpdate()
   Me.ScheduledEndDate = Me.ScheduledStartDate
   Me.ActualEndDate = Me.ScheduledStartDate
   Me.ActualStartDate = Me.ScheduledStartDate
End Sub
This will populate all Date Fields with the same date, but allow you to manually change any or all of them, if necessary.

Linq ;0)>

Hi

I tried exactly this on the afterupdate property and it did nothing. I moved it to the onexit property and it worked, sort of. The values in the other date fields where populated with the date from the first field, you just could not see it.

If you click on the individual fields and then exit those fields you could see the values. If you only closed the form and the reopened it the values had in fact been retained. But only on the onexit event and not on the afterupdate event.
 
I tried exactly this on the afterupdate property and it did nothing.
Just to clarify, you tried the code in the AfterUpdate event of the ScheduledStartDate testbox? And after entering a date in that textbox and moving off of it and onto another control in the form, it did not immediately populate the other three textboxes,

ActualEndDate
ActualStartDate
ScheduledEndDate

with the same date?

Linq ;0)>
 
Just to clarify, you tried the code in the AfterUpdate event of the ScheduledStartDate testbox? And after entering a date in that textbox and moving off of it and onto another control in the form, it did not immediately populate the other three textboxes,

ActualEndDate
ActualStartDate
ScheduledEndDate

with the same date?

Linq ;0)>

Close

With the code in the afterupdate event it did nothing. When i moved the code to the onexit event it did work to a degree. It did populate the other three fields but it was not visible. You had to either click in the fields to see it or close and reopen the form
 
With the code in the afterupdate event it did nothing.
In the AfterUpdate event of what? The Form? A Textbox? If so, which Textbox? Please copy and post the entire, exact AfterUpdate Sub you tried.

Linq
 
In the AfterUpdate event of what? The Form? A Textbox? If so, which Textbox? Please copy and post the entire, exact AfterUpdate Sub you tried.

Linq

It is the afterupdate event of the field ScheduledStartDate. Here is the code

Code:
Private Sub ScheduledStartDate_AfterUpdate()
    Me.ScheduledEndDate = Me.ScheduledStartDate
    Me.ActualEndDate = Me.ScheduledSartDate
    Me.ActualStartDate = Me.ScheduledStartDate
End Sub
 

Users who are viewing this thread

Back
Top Bottom