Problems with if statements

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 
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.
 
Further to my last post. Just take out the Else's and have them as individual
If statements.
 
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#
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top