Change Properties of Control

L

Lloyd

The following code works to show "late" dates in a
different color on a single record form. Is there an easy
way to do it on a continuous form?

Thanks, Lloyd

Private Sub Form_Current()

If Me![NextActionDate] < Date Then
Me![NextActionDate].ForeColor = vbGreen
Me![NextActionDate].BackColor = vbBlue
Else
Me![NextActionDate].ForeColor = vbBlue
Me![NextActionDate].BackColor = vbWhite
End If

End Sub
 
D

Dirk Goldgar

Lloyd said:
The following code works to show "late" dates in a
different color on a single record form. Is there an easy
way to do it on a continuous form?

Thanks, Lloyd

Private Sub Form_Current()

If Me![NextActionDate] < Date Then
Me![NextActionDate].ForeColor = vbGreen
Me![NextActionDate].BackColor = vbBlue
Else
Me![NextActionDate].ForeColor = vbBlue
Me![NextActionDate].BackColor = vbWhite
End If

End Sub

You'd have to use the conditional formatting feature instead. That
should be available if you are running Access 2000 or later.

In design view, set the properties of [NextActionDate] the way you want
them to be normally (if the value is *not* < Date), then with that
control selected click Format -> Conditional Formatting..., set the
condition for "Field Value Is", "less than", "Date()", and pick the
ForeColor and BackColor properties you want to apply.
 
G

Guest

Thanks Dirk. You have provided me another reason to
upgrade from Access97. In the meantime, do you know of
another route to accomplish this in Access97?

Lloyd
-----Original Message-----
The following code works to show "late" dates in a
different color on a single record form. Is there an easy
way to do it on a continuous form?

Thanks, Lloyd

Private Sub Form_Current()

If Me![NextActionDate] < Date Then
Me![NextActionDate].ForeColor = vbGreen
Me![NextActionDate].BackColor = vbBlue
Else
Me![NextActionDate].ForeColor = vbBlue
Me![NextActionDate].BackColor = vbWhite
End If

End Sub

You'd have to use the conditional formatting feature instead. That
should be available if you are running Access 2000 or later.

In design view, set the properties of [NextActionDate] the way you want
them to be normally (if the value is *not* < Date), then with that
control selected click Format -> Conditional Formatting..., set the
condition for "Field Value Is", "less than", "Date()", and pick the
ForeColor and BackColor properties you want to apply.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.
 
D

Dirk Goldgar

Thanks Dirk. You have provided me another reason to
upgrade from Access97. In the meantime, do you know of
another route to accomplish this in Access97?

Not in any simple, general way. If you wanted to use some other sort of
highlighting, you might see if Stephen Lebans' FormatByCriteria class
would work for you: http://www.lebans.com/formatbycriteria.htm .

If you don't need to be able to edit data in this control and could live
with just the ForeColor changes (leaving BackColor alone), you could
overlay another text box on it, set that text box's BackStyle to
Transparent and its ForeColor to your highlight color, and then set the
controlsources of the original textbox to

=IIf([NextActionDate] < Date, Null, [NextActionDate])

and the controlsource of the overlaid text box to

=IIf([NextActionDate] < Date, [NextActionDate], Null)
 
T

Ted

hi,

perhaps this is along the same lines...

i have two forms, the main form and its subform. the
subform is being displayed as a continuous datasheet (oh
yeah and btw i am using A2K), and i want the color of
the 'Time_on_List' control to change from black test on
white bkgrnd to yellow text on red whenever its value is
= 30 and the value of an adjacent control on the same
subform's = "Pending".

for some reason the same VBA code works on other forms (in
Form view) which are not subforms but are viewed by the
user as a main form but it has no effect on the same
control when applied in the context i've just described.

my code is below, can you point to some obvious glitch?

Private Sub Form_Current()
Dim lngRed As Long, lngYellog As Long, lngWhite As Long,
Time_on_List As Integer

lngRed = RGB(255, 0, 0)
lngBlack = RGB(0, 0, 0)
lngYellow = RGB(255, 255, 0)
lngWhite = RGB(255, 255, 255)

Me.Time_on_List = DateDiff("d", Me.Date_on_List, Now())
If Me.Time_on_List >= 30 And Me.Outcome = "Pending" Then
Me.Time_on_List.ForeColor = lngYellow
Me.Time_on_List.BackColor = lngRed
Else
Me.Time_on_List.ForeColor = lngBlack
Me.Time_on_List.BackColor = lngWhite
End If
End Sub
-----Original Message-----
Thanks Dirk. You have provided me another reason to
upgrade from Access97. In the meantime, do you know of
another route to accomplish this in Access97?

Lloyd
-----Original Message-----
The following code works to show "late" dates in a
different color on a single record form. Is there an easy
way to do it on a continuous form?

Thanks, Lloyd

Private Sub Form_Current()

If Me![NextActionDate] < Date Then
Me![NextActionDate].ForeColor = vbGreen
Me![NextActionDate].BackColor = vbBlue
Else
Me![NextActionDate].ForeColor = vbBlue
Me![NextActionDate].BackColor = vbWhite
End If

End Sub

You'd have to use the conditional formatting feature instead. That
should be available if you are running Access 2000 or later.

In design view, set the properties of [NextActionDate] the way you want
them to be normally (if the value is *not* < Date), then with that
control selected click Format -> Conditional Formatting..., set the
condition for "Field Value Is", "less than", "Date()", and pick the
ForeColor and BackColor properties you want to apply.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.
.
 
D

Dirk Goldgar

Ted said:
hi,

perhaps this is along the same lines...

i have two forms, the main form and its subform. the
subform is being displayed as a continuous datasheet (oh
yeah and btw i am using A2K), and i want the color of
the 'Time_on_List' control to change from black test on
white bkgrnd to yellow text on red whenever its value is

for some reason the same VBA code works on other forms (in
Form view) which are not subforms but are viewed by the
user as a main form but it has no effect on the same
control when applied in the context i've just described.

my code is below, can you point to some obvious glitch?

Private Sub Form_Current()
Dim lngRed As Long, lngYellog As Long, lngWhite As Long,
Time_on_List As Integer

lngRed = RGB(255, 0, 0)
lngBlack = RGB(0, 0, 0)
lngYellow = RGB(255, 255, 0)
lngWhite = RGB(255, 255, 255)

Me.Time_on_List = DateDiff("d", Me.Date_on_List, Now())
If Me.Time_on_List >= 30 And Me.Outcome = "Pending" Then
Me.Time_on_List.ForeColor = lngYellow
Me.Time_on_List.BackColor = lngRed
Else
Me.Time_on_List.ForeColor = lngBlack
Me.Time_on_List.BackColor = lngWhite
End If
End Sub

Sorry, I didn't see this message until now.

Am I right in understanding that it's the subform you're trying to apply
this formatting to? None of these formatting properties is going to
work if the form (or subform) in question is in datasheet view. You
could, however, display the form or subform in continuous forms view
instead, with various format properties set up to make it look like a
datasheet. Then you could use conditional formatting to do what you
want.
 
G

Guest

you are correct in saying the focus of my interest lies in a subForm. and
your 2nd premise is on point as well. your closing statement(s) however are
not: i have managed to display the sub-form in datasheet view AND put in a
pair of mutually exclusive expressions into the "Conditional Formatting"
interface successfully.

your response is greatly appreciated however.

ted
 
D

Dirk Goldgar

Ted said:
you are correct in saying the focus of my interest lies in a subForm.
and your 2nd premise is on point as well. your closing statement(s)
however are not: i have managed to display the sub-form in datasheet
view AND put in a pair of mutually exclusive expressions into the
"Conditional Formatting" interface successfully.

Well, how about that! You're right, and I've learned something new
today. I didn't think conditional formatting could be applied to
datasheets, but now I see that you can. I'm sure glad you didn't trust
me, and checked it for yourself. Please accept my apologies for giving
you bad information.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top