Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If between 2 dates then colour text box

Status
Not open for further replies.

ali32uk

Technical User
Mar 31, 2011
22
0
0
GB
Hi All

Apologies but I dont know where to go with this, I just want to do an if statement which says

if StartDate falls between 01/11/2015 and 30/11/2015 then change the back colour of a textbox to red

can any one help??

I m a bit out of practice and not done coding for many years... so you help would be greatly appreciated

BR

Alastair
 
sorry I should add, I m looking to repeat this for different date so


If StartDate falls between 01/11/2015 and 30/11/2015 then
change the back colour of a textbox to red
elseif StartDate falls between 01/12/2015 and 31/12/2015 then
change the back colour of a textbox to red
elseif StartDate falls between 01/01/2016 and 31/01/2016 then
change the back colour of a textbox to red
endif


Ali
 
Conditional formatting may be the way to go, but if you want to code, something like this may help:

Code:
Dim StartDate As Date

StartDate = Cdate("1/1/2016")

If (StartDate >= CDate("01/11/2015") And StartDate <= CDate("30/11/2015")) Or _
   (StartDate >= CDate("01/12/2015") And StartDate <= CDate("31/12/2015")) Or _
   (StartDate >= CDate("01/01/2016") And StartDate <= CDate("31/01/2016")) Then 

    txtMyBox.BackColor = vbRed
Endif

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
Note that Andy's code can only be used for a Single View Form; Continuous and Datasheet View Forms require the use of Conditional Formatting off of the menu/ribbon, as suggested by Duane.

Hope this helps!

There's always more than one way to skin a cat!

All posts/responses based on Access 2003/2007
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top