Problems with if statements

A

Alylia

I have three pairs of command buttons whose enabled properties are set to
disabled. I want each of then to become enabled on form load on three
separate dates. The code that I have written for this to happen is mentioned
below:

If Date >= #7/1/2005# Then
cmdAllot6.Enabled = True
cmdReq6.Enabled = True
ElseIf Date >= #7/1/2006# Then
cmdAllot7.Enabled = True
cmdReq7.Enabled = True
ElseIf Date >= #7/1/2007# Then
cmdAllot8.Enabled = True
cmdReq8.Enabled = True
End If

If I change the date on my computer to say 23-Mar-2006, cmdAllot6 and
cmdReq6 become enabled on form load. However, if the date is changed to
23-Mar-2010, the other two pairs of command buttons do not become enabled.

There seems to be something wrong with the code.

I would appreciate if someone can rescue me urgently.
 
J

JaRa

Is this what you want?

If Date >= #7/1/2005# AND Date < #7/1/2006# Then
cmdAllot6.Enabled = True
cmdReq6.Enabled = True
ElseIf Date >= #7/1/2006# AND Date < #7/1/2007# Then
cmdAllot7.Enabled = True
cmdReq7.Enabled = True
ElseIf Date >= #7/1/2007# AND Date < #7/1/2008# Then
cmdAllot8.Enabled = True
cmdReq8.Enabled = True

End if

- Raoul
 
D

Dennis

You need to put your latest date in the 'If' first. 23-Mar-2010 is greater or
equal to 7/1/2005 so the first part of the 'if' is true and it never gets to
the Else part.
 
D

Dennis

Further to my last post. Just take out the Else's and have them as individual
If statements.
 
S

Steve Schapel

Alylia,

Try it like this...
cmdAllot6.Enabled = Date >= #7/1/2005#
cmdReq6.Enabled = Date >= #7/1/2005#
cmdAllot7.Enabled = Date >= #7/1/2006#
cmdReq7.Enabled = Date >= #7/1/2006#
cmdAllot8.Enabled = Date >= #7/1/2007#
cmdReq8.Enabled = Date >= #7/1/2007#
 
Top