473,395 Members | 1,623 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,395 software developers and data experts.

Changing field color based on date data for each record

2
Greetings,

I am creating a "stoplight" type report that is based on the number of days between dates, the field will be highlighted in red, yellow, or green. I am able to change the background color on the textbox, but each subsequent record is set to the color as determined by the first record. Is there a way to do this for each record? I am using access 97. My code is something like this (I'm going off of memory as I left my code at work):

Dim mydate1 As Date, mydate2 As Date
Dim lngRed As Long, lngGreen As Long

db = DAO.database
rs = DAO.recordset

Set db = connect.database()
Set rs = db.connect("queryname")...can't remember exactly, its been a long day

rs.movefirst
Do until rs.eof
If mydate1 - mydate2 >3 Then
Me.dateofinterest.backcolor = lngRed
Else
Me.dateofinterest.backcolor = lngGreen
End If
rs.movenext
Loop

rs.close
set db = nothing
set rs = nothing

Anyhow, the code seems to work as is and is set to the form open event (I also tried form load), but it sets every text box to the color based on the if statement for the first record. I have also tried creating a bunch of subforms, but each opens in the first record. I realize that since each textbox is named the same thing in the form, that is why it is doing it.

Does anyone know of a different/better/easier way in access 97?
Jun 22 '07 #1
3 6054
missinglinq
3,532 Expert 2GB
If this is a Single View form (where you view one record at a time) you can accomplish your task by placing your code in the Form_Current() event. If your form is Datasheet or Continuous you're not going to be able to do this in Access 97. Later versions of Access have a function called Conditional Formating that would allow you to do this for a continuous form, but not for your version.

If your code was working as far as setting the color right vis a vis the first record then all you should need is

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.  
  3. Dim mydate1 As Date, mydate2 As Date
  4. Dim lngRed As Long, lngGreen As Long
  5.  
  6.   If mydate1 - mydate2 >3 Then
  7.     Me.dateofinterest.backcolor = lngRed
  8.   Else
  9.    Me.dateofinterest.backcolor = lngGreen
  10.   End If
  11.  
  12. End Sub
If you have any further trouble, let us know.

Good Luck!

Linq
Jun 22 '07 #2
kevinj
2
Linq,

Thanks for the info. I am using a continuous form as the goal is to see many records at the same time. Do you know if there is a way to do this using a report instead of a form maybe?

Thanks!
Jun 22 '07 #3
ADezii
8,834 Expert 8TB
Linq,

Thanks for the info. I am using a continuous form as the goal is to see many records at the same time. Do you know if there is a way to do this using a report instead of a form maybe?

Thanks!
Place comparable code in the Format Event (Detail Section) of the Report.
Jun 22 '07 #4

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

Similar topics

8
by: mark | last post by:
Access2000 How do I write a query that combines the CTC field from each record below into one record? I need to concatenate the CTC field with a separator, like below: ...
16
by: StenKoll | last post by:
Help needed in order to create a register of stocks in a company. In accordance with local laws I need to give each individual share a number. I have accomplished this by establishing three tables...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
9
by: MLH | last post by:
I have a database (datatrek.mdb) with a table named DATA. The table has a date/time field with default value = Now(). It has 100 records in it entered over a 50-minute period. I would like the...
1
by: Scott269 | last post by:
So I've got an old MS Works database I imported into Access. I needed a primary key so I created a record number field that was just the record number I manually inserted when I entered it in the...
7
by: astro | last post by:
Anyone have suggestions on where to troubleshoot this error? Background: -Access 2k v. 9.0.6926 sp3 - front and backend on production server (wiindows 2k) -accessed via Citrix -front-end is...
14
by: Tina | last post by:
My employer tracks productivity/performance of clinicians (how much they bill) each week, its averages for the month, and the 6 months. These averages are compared to their expected productivity....
6
by: KevinPreston | last post by:
Hello everyone, this is my first post so apologies if i dont get it right first time, i am a self taught Access user, i am stuck on something i am trying to do, briefly i have 2 tables, one for...
2
by: dympna | last post by:
Hi can anyone suggest a fix for this... as I am a novice in access. I have created a training table with the following fields Employee Name - joe Training Received - Fork lift Date Received...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.