Simple If/Then I'm screwing up

mitchem1

Registered User.
Local time
, 21:23
Joined
Feb 21, 2002
Messages
153
If Month(Date) > 6 Then
FiscalYear.Value = Year(Date)
Else
FiscalYear.Value = Year(Date) + 1
End If


Since Month(Date) = 7, I was hoping this would return 2011, but it returns 2010. The + 1 must not work?? Thanks for any help.
 
I am going to venture a guess and say that because your using the Year and Date function then it's a date. which would mean you would have to add using DateSerial.

I THINK you might be able to just add a variable to the cause.

Dim a variable as an integer. lets call it MyYear

...
Myyear = Year(Date)
MyYear = MyYear +1
FiscalYear.value = MyYear
End if
 
The general arrangement of an if statement is...
Code:
if <condition test>
....code to execute if condition test is true
Else
....code to execute if condition test is false
end if
As written, your if statement returns the current year if the month is greater than 6 or, if the current month is less than or equal to 6, it returns the current year +1.

If you want the reverse situation to what you're getting now, then you either need to change the condition test or swap the order of the code snippets inside the if.

e.g.,
Code:
If Month(Date) [COLOR="Blue"]<=[/COLOR] 6 Then
   FiscalYear.Value = Year(Date)
Else
   FiscalYear.Value = Year(Date) + 1
End If

should work, as would
Code:
[code]
If Month(Date) >6 Then
   [COLOR="blue"]FiscalYear.Value = Year(Date) + 1[/COLOR]
Else
   [COLOR="blue"]FiscalYear.Value = Year(Date) [/COLOR]
End If
[/code]
 
Very good catch for CraigDolphin, although Accessguy's point about not using a System Function (date) as a variable name is also true. If you meant to use the System Function, then date() would be the way to go.
 
Thanks AccessGuy 49,
Using the variable worked like a charm.
 

Users who are viewing this thread

Back
Top Bottom