Showing a label based on date()

GrahamUK33

Registered User.
Local time
Today, 16:17
Joined
May 19, 2011
Messages
58
MS Access 2002 (MS Office XP)

I would like to make a label only visible (containing a warning) if a date (in a text box) is shown to be less than today’s date.

Any ideas as to what code I will need and what event to put it on?
 
In the form's Current event and the text box's After Update event:

Me.labelNameHere.Visible = (Me.TextBoxnameHere < Date())
 
Many thanks Bob, that has worked. :)
 
Im trying to change the fore colour (to red) of another lable based on the date as well.

Would it be something like:
Me.lblDateValidUntil.ForeColor=255 = (Me.DateValidUntil < Date())

Would I also need to place the code in the same location as in your last reply?
 
That is a slightly different one which would need to be:
Code:
If  Me.DateValidUntil < Date()
   Me.lblDateValidUntil.ForeColor = 255
End If

and yes, it would go in the same two events.
 
It fails on this line:
If Me.DateValidUntil < Date()

Any other ideas?
 
Microsoft Visual Basic

Compile error:
Syntax error


Then the following is highlighted in blue:
If Me.DateValidUntil < Date()
 
Microsoft Visual Basic

Compile error:
Syntax error


Then the following is highlighted in blue:
If Me.DateValidUntil < Date()

The statement must include a "then" such as

If Me.DateValidUntil < Date() then
 
The statement must include a "then" such as

If Me.DateValidUntil < Date() then

I can't believe I missed that (I need some sleep) -

headinhands.jpg
 
Bob if this was the only thing I miss, life would be great.
 
Thanks for you help guys, its getting there but I have another error now:

Microsoft Visual Basic

Compile Error:
Block If without End If

Any ideas?
 
Thanks for you help guys, its getting there but I have another error now:

Microsoft Visual Basic

Compile Error:
Block If without End If

Any ideas?

Post the code for the entire procedure (remember to use code tags here so it is easier to read - screenshot provided below just in case you don't know how).

codetag001.png
 
To add to what Bob has explained. This message is because you are using a nexted "IF" statement which must end with "End If". Look at Bob's entry number three it is

If Me.DateValidUntil < Date() then
Me.lblDateValidUntil.ForeColor = 255
End If


When you enter the statements for the then on another line you must end the block with End If.

Or you could code:

If Me.DateValidUntil < Date() then Me.lblDateValidUntil.ForeColor = 255

When its on one line you do not need an End If
 
Many thanks for your help, it is nearly there.

This works only if there is a date in the date field. What will I need to add if there is no date to make a warning in red?

'Out of date warning
Me.boxDisclosure.Visible = (Me.DateValidUntil < Date)

'Out of date warning
If Me.DateValidUntil < Date Then Me.lblDateValidUntil.ForeColor = 255
If Me.DateValidUntil > Date Then Me.lblDateValidUntil.ForeColor = 12632256
 
I have managed to find the answer to the last question.

I have used the code below which seems to work:

If IsNull(Me.DateValidUntil) Then
Me.boxDisclosure.Visible = False
Else
Me.boxDisclosure.Visible = (Me.DateValidUntil < Date)
End If



Thanks guys for your help with this, very much appreciated. :)
 

Users who are viewing this thread

Back
Top Bottom