INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

If between 2 dates then colour text box

If between 2 dates then colour text box

(OP)
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

RE: If between 2 dates then colour text box

(OP)
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

RE: If between 2 dates then colour text box

Have you looked at conditional formatting? You can use "Expression Is" to enter your conditions.

Duane
Hook'D on Access
MS Access MVP

RE: If between 2 dates then colour text box

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.

RE: If between 2 dates then colour text box

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close