473,406 Members | 2,849 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Change color of field depending on Date (was How to include OnTimer event?)

Hi All,

I want to include some code for the OnTimer event in my Form "frmDueDateList"

But when i open the form in the design view and checked the properties menu,
i could not find the OnTimer event.

I want to change the color of the DueDate field to Red if it is less than the current Date. I thought it could be done under OnTimer event.

so i included the following code on Form_Load but there was no change in the DueDate field ForeColor for those which are less than the current Date:

Private Sub Form_Load()

If [Ins_NextDueDate] < Date Then

If [Ins_NextDueDate].ForeColor = vbRed Then
[Ins_NextDueDate].ForeColor = vbBlack
Else
[Ins_NextDueDate].ForeColor = vbRed
End If
End If
End Sub

Need your assistance.

Thanks,
Kathy
Aug 9 '07 #1
8 2636
FishVal
2,653 Expert 2GB
Hi All,

I want to include some code for the OnTimer event in my Form "frmDueDateList"

But when i open the form in the design view and checked the properties menu,
i could not find the OnTimer event.

I want to change the color of the DueDate field to Red if it is less than the current Date. I thought it could be done under OnTimer event.

so i included the following code on Form_Load but there was no change in the DueDate field ForeColor for those which are less than the current Date:

Private Sub Form_Load()

If [Ins_NextDueDate] < Date Then

If [Ins_NextDueDate].ForeColor = vbRed Then
[Ins_NextDueDate].ForeColor = vbBlack
Else
[Ins_NextDueDate].ForeColor = vbRed
End If
End If
End Sub

Need your assistance.

Thanks,
Kathy
Hi, Kathy.

Handling OnTimer event is not useful this case. Why not just to apply conditional formatting on the "field"?
Aug 9 '07 #2
Hi, Kathy.

Handling OnTimer event is not useful this case. Why not just to apply conditional formatting on the "field"?
Hi,

Thanks for your reply

I did not use the On Timer event but i just used the following code on Form Load.
I get the Message to be displayed if the date is less then the current date but the ForeColor is still the same. For some reason, it is not happy with the code

Private Sub Form_Load()

If [Ins_NextDueDate] < Date Then

[Ins_NextDueDate].ForeColor = vbRed

Else

[Ins_NextDueDate].ForeColor = vbBlack

MsgBox "Due Date is exceeded. Please inform the customer"

End If

Need your assistance.

Thanks.
End Sub
Aug 10 '07 #3
missinglinq
3,532 Expert 2GB
What kind of form is this? Single View, Continuous or Datasheet?

BTW, any conditional formatting placed in the FormLoad event will only be applied against the first record to load, not against all records. This type of code needs to be in the Form_Current event, and depending on the type of form, may or may not do the job you want.

Linq ;0)>
Aug 10 '07 #4
Scott Price
1,384 Expert 1GB
If [Ins_NextDueDate] < Date Then
In this line of code, unless Date is a variable that you have declared elsewhere, try Now() instead.

Regards,
Scott

Added... And shouldn't your message box actually be in the same section of code that changes the color to red?
Aug 10 '07 #5
missinglinq
3,532 Expert 2GB
Scott, Date() is an Access function! It returns the current date, and is perefectly acceptable here. There's no valid reason to use Now() which returns both date and time.

Linq
Aug 10 '07 #6
FishVal
2,653 Expert 2GB
Hi,

Thanks for your reply

I did not use the On Timer event but i just used the following code on Form Load.
I get the Message to be displayed if the date is less then the current date but the ForeColor is still the same. For some reason, it is not happy with the code

Private Sub Form_Load()

If [Ins_NextDueDate] < Date Then

[Ins_NextDueDate].ForeColor = vbRed

Else

[Ins_NextDueDate].ForeColor = vbBlack

MsgBox "Due Date is exceeded. Please inform the customer"

End If

Need your assistance.

Thanks.
End Sub
Hi, Kathy.

To apply this via code you need to handle Load, Current and AfterUpdate (on the field) event to ensure the field appearance to be relevant in any case.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.     CheckDueDate
  3. End Sub
  4.  
  5. Private Sub CheckDueDate()
  6.  
  7.     With Me.Ins_NextDueDate
  8.         If .Value < Date Then
  9.             .ForeColor = vbRed
  10.             MsgBox "Due Date is exceeded. Please inform the customer"
  11.         Else
  12.             .ForeColor = vbBlack
  13.         End If
  14.     End With
  15.  
  16. End Sub
  17.  
  18. Private Sub Form_Load()
  19.     CheckDueDate
  20. End Sub
  21.  
  22. Private Sub Ins_NextDueDate_AfterUpdate()
  23.     CheckDueDate
  24. End Sub
  25.  
But, again, why do you not like to use conditional formatting?
Aug 10 '07 #7
Scott Price
1,384 Expert 1GB
Scott, Date() is an Access function! It returns the current date, and is perefectly acceptable here. There's no valid reason to use Now() which returns both date and time.

Linq
That's fine, Linq, but doesn't she still need to add the ()??? That was my whole point in mentioning the Now()... To call attention to that line of code...

Regards,
Scott

Just re-checked, and the () are not nec... Sorry for the bother.
SP
Aug 10 '07 #8
missinglinq
3,532 Expert 2GB
Exactly, Scott!

FishVal, why is the code necessary in the Form_Load event? Form_Current will apply it to every record, right?

Linq ;0)>
Aug 10 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Laurence Neville | last post by:
This is regarding a change in the Short Date format under Hebrew Regional Settings, that has caused huge problems in our ASP web application. The change appears to have been introduced sometime...
4
by: Richard Cornford | last post by:
For the last couple of months I have been trying to get the next round of updates to the FAQ underway and been being thwarted by a heavy workload (the project I am working on has to be finished an...
4
by: Dr John Stockton | last post by:
It looks as if the USA may be changing its Summer Time (DST) Rules, perhaps with immediate effect. Browsers use the rules selected in the OS, and I predict that in many cases the rules will not...
6
by: Rey | last post by:
Howdy, all. Appreciate your help. Have a one to many relation between a client and visit table. In the visit subform, I have a visittype and counselor field which are comboboxes. If I set...
1
by: Luke Duke | last post by:
vc++ v7.1 Whenever I add an OnTimer message handler via the properties pane, I get the following code added to my files: afx_msg void OnTimer(UINT nIDEvent); - and - void...
1
by: Tony | last post by:
Hi, I have two forms A and B, both opened. In form A, I programmatically change the Date of Birth field of the current record of form B. I noticed that form B automatically displays the new data...
2
by: planetthoughtful | last post by:
Hi All, I have a calendar form that updates a date field on the form from which it was called. I have code in the OnChange event of the date field that I would like performed whenever the date...
3
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when...
5
by: Rex | last post by:
Hi, I want to change a value in one table depending on the value(s) in another table. I am trying to achieve this in a form. to elaborate I have a many-to-many relationship between tables...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.