if > this year + 10

  • Thread starter Thread starter deb
  • Start date Start date
D

deb

I my subform, there is a textbox called OutageYYYY.
If the OutageYYYY is greater than 10 past this year, give msg.

I tried,

If [OutageYYYY] > ((Year(Date())) + 10) Then
MsgBox "Outage year is more than 10 years out. Please verify.", vbOKOnly,
"Verify Outage Year."
End If
End Sub

keeps changing to ... as soon as I move my curser off of the code

If [OutageYYYY] > ((Year(Date)) + 10) Then

What is the correct code?
 
Access often removes the () after the Date function when you call it. I don't
think it should ever do that, but it does. On the other hand, the code does
continue to work even if the parentheses are removed.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
And you can prevent this *undesired* behaviour by partially/fully qualifying
the function
ie
VBA.Date() or VBA.DateTime.Date() (*don't* try that in a query though - or
ommitting ().. )

pieter

John Spencer MVP said:
Access often removes the () after the Date function when you call it. I
don't think it should ever do that, but it does. On the other hand, the
code does continue to work even if the parentheses are removed.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
I my subform, there is a textbox called OutageYYYY.
If the OutageYYYY is greater than 10 past this year, give msg.

I tried,

If [OutageYYYY] > ((Year(Date())) + 10) Then
MsgBox "Outage year is more than 10 years out. Please verify.",
vbOKOnly, "Verify Outage Year."
End If
End Sub

keeps changing to ... as soon as I move my curser off of the code

If [OutageYYYY] > ((Year(Date)) + 10) Then

What is the correct code?
 
Back
Top