Another Quick Simple VBA question (if...then statement)

  • Thread starter Thread starter abxy
  • Start date Start date
A

abxy

in VB, how do i write:

if Combobox1 = "January" and today's date(system date) isn't equal t
2/2/04 or later then checkbox1.enabled = false

thanks! :
 
abxy,
You're practically there with your English:

If (ComboBox1.Text="January") AND (Now()<#2/2/04) Then
CheckBox1.Enabled = False
End If

The backets are not required, but it makes the logic clearer.
Also, I don't think you really want to hard code a date, especially one that
is already in the past.

NickHK
 
if combobox1.Text = "January" and date < DateValue("2/2/2004") Then
checkbox1.Enabled = False
End if
 
Hi
If ComboBox1.Value = "January" then
If Date<2/2/04 then
CheckBox1.enabled = False
end if
end if

should work. This assumes that you are using the US date syntax of
mm/dd/yy. If that is a problem, you might be better off using the
DateSerial or DateValue functions. For example, using the date 3/2/04
to mean 2nd Mar 2004 (US syntax) you can make it less ambiguous for
non US users by writing
DateSerial(04,3,2)
, or by using an unambiguous date format by writing
DateValue("Mar 2, 2004")

So that your first If statement is now
If Date<DateSerial(04,3,2) then

regards
Paul
 
Thanks everyone, you all were a big help...Actually last night,
wasn't getting any response so i just decided to fool around and I cam
up with a solution but it wasn't working properly(working in som
cases, but then not in others); it was this:

If cboMonth.Value = "Febuary" And Date > "2/06/04" Then

chkWk1.Enabled = True

End If

then I saw you all's repsonses this morning and so i altered it t
this:

If cboMonth.Value = "Febuary" And Date > DateValue("2/06/04") Then

chkWk1.Enabled = True

End If

and it works perfect now...i guess the statement DateValue was neede
to fine tune things

Thank you veeeeeerry much everyone, i really appreciate you all's help
 
Goddamit!
Caught me out not testing before, and here I go doing it again...
cheers
Paul
 
Back
Top