Variable in a Date Calculation

Gilrucht

Registered User.
Local time
Today, 15:07
Joined
Jun 5, 2005
Messages
132
I have the following date calculation :
-----------------
Private Sub StatofLimits_GotFocus()
'--Determines Statute of Limitations accounting for minors.
If DateAdd("yyyy", 18, Me.Txt14) > Me.txtBegin Then
Me.StatofLimits = DateAdd("yyyy", 20, Me.Txt14)
Else
Me.StatofLimits = DateAdd("yyyy", 2, Me.txtBegin)
End If
End Sub
------------------------
Here is my problem. The number "2" in the else statement (Me.StatofLimits = DateAdd("yyyy", 2, Me.txtBegin)in the above example is a variable. The variable is selected from a combobox and stored in an unbound textbox. The variable will always represent a number of years-ie 3 years, 4 years, etc. I need to modify my calculation so that it will pull the variable from my textbox:
I know this isn't correct but this is what I need:

Me.StatofLimits = DateAdd("yyyy", (Number from MyTxtBox), Me.txtBegin)



Can anyone give me the correct syntext?

Pat, If you read this, I did listen. The reason I need to modify my calculation and use a variable is because I moved my Statute of Limitation Dates to the same table and different case types have different Statutes. They can be anywhere from 2 to 6 years.
 
Last edited:
You should be able to use the Me.TxtBoxName (replace TextBoxName with your control)
 
Thanks, FoFa that worked but I realized I have a similar issue with the IF side of the statement as well:

If DateAdd("yyyy", 18, Me.Txt14) > Me.txtBegin Then
Me.StatofLimits = DateAdd("yyyy", 20, Me.Txt14)

The number "20" is also now a variable. This number is determined by adding 18 to the value of the same unbound textbox whch contains the variable used in the Else Statement:

If DateAdd("yyyy", 18, Me.Txt14) > Me.txtBegin Then
Me.StatofLimits = DateAdd("yyyy", {18 + Me.MyTxtBox}, Me.Txt14)
Else
Me.StatofLimits = DateAdd("yyyy", Me.MyTextBox, Me.txtBegin)
End If

I have the else Statement working but now need the correct syntext for the if statement. I need to add 18 to the value of "Me.MyTextBox" in the IF Statement. Can anyone help?
 
Take away the brackets and it should work.

Me.StatofLimits = DateAdd("yyyy", 18 + Me.MyTxtBox, Me.Txt14)
 
Well I am assuming the data type is being converted for you, are you getting an error?
 

Users who are viewing this thread

Back
Top Bottom