D
Dennis
Hi,
I'm runnining Access 2003.
I allow the user to enter a two digit number for the year and then want to
expand it to a 4 digit year.
I have some edits and the code to add either 1900 or 2000 to the 2 digit
date. My question is where do I put the code - in the Before Update or After
Update event for the text box.
The following code is currently in the text box's Before Update event:
Dim intCurrYr As Integer
Dim strErrMsg As String
Dim intErrButton As Integer
Dim strMsgResp As String
intCurrYr = Format(Date, "yyyy")
If IsNull(Me.txtMilEntryYr) = False Then
If IsNumeric(Me.txtMilEntryYr) Then
If Me.txtMilEntryYr >= 0 And Me.txtMilEntryYr <= 29 Then
Me.txtMilEntryYr = 2000 + Me.txtMilEntryYr '
Default 0 to 29 to 2000 thru 2029
End If
If Me.txtMilEntryYr >= 30 And Me.txtMilEntryYr <= 99 Then
Me.txtMilEntryYr = 1900 + Me.txtMilEntryYr
End If
' If the date is before 1930 or after the Current Year, then
display an error message and cancel the field update.
If Me.txtMilEntryYr < 1930 Or Me.txtMilEntryYr > intCurrYr Then
Cancel = True
intErrButton = vbOKOnly + vbCritical
strErrMsg = "You entered of " & Me.txtMilEntryYr & "for the
year is invalid." & vbCrLf
strErrMsg = strErrMsg & "Please enter a year that is between
1930 and " & intCurrYr & "."
strMsgResp = MsgBox(strErrMsg, intErrButton, "Military Entry
Year is incorrect")
End If
End If
End If
Everything works ok, but when it executes the line
Me.txtMilEntryYr = 1900 + Me.txtMilEntryYr
I recevie a error message:
"The macro or function set to the BeforeUpdate or ValidationRule property
for this field is preventing Access from saving the data in the field."
I'm guessing that I can not change the value of txtMilEntryYr within the
Before Update event.
What is the best way to accomplish adding 1900 or 2000 to the 2 digit year?
I'm runnining Access 2003.
I allow the user to enter a two digit number for the year and then want to
expand it to a 4 digit year.
I have some edits and the code to add either 1900 or 2000 to the 2 digit
date. My question is where do I put the code - in the Before Update or After
Update event for the text box.
The following code is currently in the text box's Before Update event:
Dim intCurrYr As Integer
Dim strErrMsg As String
Dim intErrButton As Integer
Dim strMsgResp As String
intCurrYr = Format(Date, "yyyy")
If IsNull(Me.txtMilEntryYr) = False Then
If IsNumeric(Me.txtMilEntryYr) Then
If Me.txtMilEntryYr >= 0 And Me.txtMilEntryYr <= 29 Then
Me.txtMilEntryYr = 2000 + Me.txtMilEntryYr '
Default 0 to 29 to 2000 thru 2029
End If
If Me.txtMilEntryYr >= 30 And Me.txtMilEntryYr <= 99 Then
Me.txtMilEntryYr = 1900 + Me.txtMilEntryYr
End If
' If the date is before 1930 or after the Current Year, then
display an error message and cancel the field update.
If Me.txtMilEntryYr < 1930 Or Me.txtMilEntryYr > intCurrYr Then
Cancel = True
intErrButton = vbOKOnly + vbCritical
strErrMsg = "You entered of " & Me.txtMilEntryYr & "for the
year is invalid." & vbCrLf
strErrMsg = strErrMsg & "Please enter a year that is between
1930 and " & intCurrYr & "."
strMsgResp = MsgBox(strErrMsg, intErrButton, "Military Entry
Year is incorrect")
End If
End If
End If
Everything works ok, but when it executes the line
Me.txtMilEntryYr = 1900 + Me.txtMilEntryYr
I recevie a error message:
"The macro or function set to the BeforeUpdate or ValidationRule property
for this field is preventing Access from saving the data in the field."
I'm guessing that I can not change the value of txtMilEntryYr within the
Before Update event.
What is the best way to accomplish adding 1900 or 2000 to the 2 digit year?