Kamis, 15 September 2011

[MS_AccessPros] Re: BackColor on load and update problem

 

This is not practical to do in a form in code. You can do it in a report because it has a detail format event. In versions starting in 2000, your simplest solution is to use Conditional Formatting. Prior to 2007 it was in Format/Conditional Formatting. In 2007 and 2010, it's on the Design tab of the ribbon.

Paul

--- In MS_Access_Professionals@yahoogroups.com, "nigelhjackson" <nigel@...> wrote:
>
> Hi all, long time away! As I haven't done any Access work for yonks I've seemingly forgotten the little I used to know! Could someone help with this please...
>
> I am putting together a very simple warranty database. The single form will show continuous records with fields SerialNumber, PartNumber, SDNNumber (this is the delivery note), SDNDate, WarrantyExpiryDate, WarrantyDaysLeft.
>
> When the form is loaded, I want WarrantyExpiryDate and WarrantyDaysLeft to have green BackColor if warranty is valid, and red BackColor if not. When a new record is added, it will obviously have green backgrounds until 456 days later, when the background will then be red.
>
> The problem I have is that when the form opens ALL the records are red or green depending on whether the first record is in or out of warranty, and if I change the SDNDate (thus changing the warranty start date) all records change to green or red depending on the date I enter...as opposed to each record showing green or red as appropriate.
>
> The simple (and obviously wrong!) code for the form load and updating after the SDNDate is entered is...
>
>
> Private Sub Form_Load()
>
> If Date - 1 >= Me.WarrantyExpiryDate Then
> Me.WarrantyExpiryDate.BackColor = 255
> Else
> Me.WarrantyExpiryDate.BackColor = 8421376
> End If
>
> If Date - 1 >= Me.WarrantyExpiryDate Then
> Me.WarrantyDaysLeft.BackColor = 255
> Else
> Me.WarrantyDaysLeft.BackColor = 8421376
> End If
>
> End Sub
>
> Private Sub SDNDate_AfterUpdate()
>
> Me.WarrantyExpiryDate = Me.SDNDate + 455
> Me.WarrantyDaysLeft = Me.WarrantyExpiryDate - Date
> Me.Refresh
>
> If Date - 1 >= Me.WarrantyExpiryDate Then
> Me.WarrantyExpiryDate.BackColor = 255
> Else
> Me.WarrantyExpiryDate.BackColor = 8421376
> End If
>
> If Date - 1 >= Me.WarrantyExpiryDate Then
> Me.WarrantyDaysLeft.BackColor = 255
> Else
> Me.WarrantyDaysLeft.BackColor = 8421376
> End If
>
> End Sub
>
> Cheers, Nige
>

__._,_.___
Recent Activity:
MARKETPLACE
A bad score is 598. A bad idea is not checking yours, at freecreditscore.com.

Stay on top of your group activity without leaving the page you're on - Get the Yahoo! Toolbar now.

.

__,_._,___

Tidak ada komentar:

Posting Komentar