clear setfocus color after velidation (1 Viewer)

kobiashi

Registered User.
Local time
Today, 14:12
Joined
May 11, 2018
Messages
258
so i have an if statement that looks at two fields and checks whether they are in a 28 day period, if not then one of the fields are colored in red to highlight the problem

two questions,

in the sub form, it is a continous form, currently when the data is wrong and the field is colored, all the fields are colored the same, how can i just select the field with the incorrect date, as apose to all the fields whether they are wrong ir not.,

secondly, once the error has been fixed, how can i then clear the color from the fields?

here is my if statement so far

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    Dim PeriodDate As Date
    Dim WashDate As Date

    PeriodDate = Me.Parent.txtPeriodCommence
    WashDate = Me.txtWashDate

    If WashDate > DateAdd("d", 28, PeriodDate) Then
        MsgBox "Sorry, but the date you have entered is outside the period, please enter a date within 28 days of the period commencing date."
        Me.txtWashDate.SetFocus
        Me.txtWashDate.BackColor = vbRed
    Cancel = True
    End If
End Sub
 

Isskint

Slowly Developing
Local time
Today, 14:12
Joined
Apr 25, 2012
Messages
1,302
Conditional formatting seems to be the answer here.
 

kobiashi

Registered User.
Local time
Today, 14:12
Joined
May 11, 2018
Messages
258
thanks for the pointer

so one field is on a form and the other field is on a sub form attached to the main form

so would i do some thing like

Code:
value is = equal or greater than
[form]![Form_ENG_MCU_Washing_NewEntry]![txtPeriodCommence]
 

kobiashi

Registered User.
Local time
Today, 14:12
Joined
May 11, 2018
Messages
258
Cheers, can I use DateAdd () as well?

So I need the greater value to be no more than PeriodCommence +28, so would that be

Code:
DataAdd("d", 28, [forms]![Form_ENG_MCU_Washing_Newentry]![txtPeriodCommence])
 

Isskint

Slowly Developing
Local time
Today, 14:12
Joined
Apr 25, 2012
Messages
1,302
Yep, you should be able to use the dateadd() function.
 

Users who are viewing this thread

Top Bottom