Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How make copy on a textbox on a report red

Posted on 2011-03-23
5
Medium Priority
?
242 Views
Last Modified: 2012-06-27
I am trying to make the value in a date textbox turn red if certain criteria exists.  Here is my code but it is not turning red.  I have this in the onformet event of the detail section of the report.

    If Me.txtFinApprovalDueDate < Now() And Me.txtFinApprovalRecdDate = "" Then
        Me.txtFinApprovalDueDate.ForeColor = vbRed
    End If

What is wrong with this?
0
Comment
Question by:SteveL13
  • 3
5 Comments
 
LVL 4

Expert Comment

by:MaximumIQ
ID: 35202435
I'm not sure what the date format is in your box but "Now" returns full date and time, if that's a different format than your box, Excel might be having a hard time calculating it. You should try the "DateDiff" function, which should account for different date/time formats or try setting the format of your "Now"

Datediff("d",<Date1>, <Date2>)
0
 
LVL 23

Expert Comment

by:Michael Fowler
ID: 35202446
I don't believe that the if statement can ever be true as it states that the date being tested must be less than now AND empty. Try changing this to

If Me.txtFinApprovalDueDate < Now() Or Me.txtFinApprovalRecdDate = "" Then

Michael
0
 
LVL 4

Accepted Solution

by:
MaximumIQ earned 2000 total points
ID: 35202557
They're two different boxes Michael74. one is Approval Due and the other is Approval Received. So it sounds like he wants it to go red, if it's past the due date and it has no value in the approval received box.

By the way I just thought about it, and DateDiff won't work for you because lets say you tell it if the datediff is 0 then blah blah, that will only work if the date of the box and today's date are the same but not if it's newer or older.

Try the code below. I tested it and it works
 
If DateValue(Me.txtFinApprovalDueDate.Text) < DateValue(Now) Then
        Me.txtFinApprovalDueDate.ForeColor = vbBlack
    End If

Open in new window

0
 
LVL 4

Expert Comment

by:MaximumIQ
ID: 35202578
This applies to Excel and should stay in the Excel Zone
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 35202616
SteveL13, you might like to ask CS to add a zone to this question.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question