I know you're thinking "God help me!", but VB coding is the best way to get exactly what you want in Access.
It's not as complex as you might think, most of it is logic. Try implementing the following code with your objects' (Controls') names:
Make sure you create a text box or label for the calculated difference in dates.
Assign your variables:
- Dim vblDate1 As Date
-
Dim vblDate2 As Date
-
Dim vblDateDiff As Integer
Be sure to name your text boxes accordingly;
I use the prefix txt for TextBox, lbl for Label, btn for Button, vbl for Variable to ensure that I don't use reserved names:
- Private Sub btnCalc_Click()
-
txtDate1.SetFocus
-
vblDate1 = CDate(txtDate1.Text)
-
txtDate2.SetFocus
-
vblDate2 = CDate(txtDate2.Text)
-
vblDateDiff = DateDiff("y", vblDate1, vblDate2)
-
Text5.SetFocus
-
Text5.Text = vblDateDiff & " Days"
-
End Sub
"y" returns the number of days between the two dates.
You need to set focus of the controls you are referencing before taking or setting properties.
CDate converts the String or Numeric value to Date format so that DateDiff can recognise and utilise the format effectively.
I hope this has resolved the issue and that it has given some insight.
Corster.