Okay, Sarah! I'll take about 60 seconds to fix this!
First off, sometimes (
not always) if you write code in the code editor without gaining access to the code editor by going thru the Properties box for a control, the control and the code are not, for lack of a better word, "connected!" In other words, although you have code for the OnClick event of a button, that code doesn't fire when the button is clicked. The answer to this is exactly what you need to do.
In Design View for your form, Right Click on your textbox
txtRevisedCompletionDate. Click on
Properties - Events. You'll notice that there's nothing in the
AfterUpdate propertry box, although in fact you do have code for this in the code module! Click on the empty box, then click on [
Event Procedure]. It should now appear in the box. Click on the ellipses (
...) to the right of the box. You should be taken to the code window and in or near the code
- Private Sub txtRevisedCompletionDate_afterupdate()
-
'Me.txtMonthsOverdue = Me.DateDiff("m", [txtTargetCompletionDate], [txtRevisedCompletionDate])
-
End Sub
You need to change two things in this code.
First, delete the apostrophe where you had this code commented out.
Second, change
Me.DateDiff("m", [txtTargetCompletionDate], [txtRevisedCompletionDate])
to
DateDiff("m", [txtTargetCompletionDate], [txtRevisedCompletionDate])
Notice that the
Me. before DateDiff is gone!
So the code should now read
- Private Sub txtRevisedCompletionDate_afterupdate()
-
Me.txtMonthsOverdue = DateDiff("m", [txtTargetCompletionDate], [txtRevisedCompletionDate])
-
End Sub
Now, delete all the other code where you tried to do this, so you're only left with the
txtRevisedCompletionDate_afterupdate() sub. The calculation will now be run
and the results stored in your table.
Linq
;0)>