Simple If/Then I'm screwing up (1 Viewer)

mitchem1

Registered User.
Local time
Today, 05:31
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.
 

Access_guy49

Registered User.
Local time
Today, 06:31
Joined
Sep 7, 2007
Messages
462
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
 

CraigDolphin

GrumpyOldMan in Training
Local time
Today, 03:31
Joined
Dec 21, 2005
Messages
1,582
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]
 

MSAccessRookie

AWF VIP
Local time
Today, 06:31
Joined
May 2, 2008
Messages
3,428
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.
 

mitchem1

Registered User.
Local time
Today, 05:31
Joined
Feb 21, 2002
Messages
153
Thanks AccessGuy 49,
Using the variable worked like a charm.
 

Users who are viewing this thread

Top Bottom