User wants color-filled fields when data isn't entered.

M

Mary A Perez

The following code I placed in the "after update" event, but it's not doing
what I want it to do. Basically, I want those fields that do not have data
typed in them to turn the color of the form which is light green, & if data
is entered the field to be a white backcolor.
Thanks for your help.

Private Sub TermDate_AfterUpdate()
If IsNull(Me.TermDate) Or Me.TermDate = "" Then
Me.[TermDate].BackColor = 13434828 ' change to light green
Else
Me.[TermDate].BackColor = 16777215 ' change to white
End If
End Sub
 
M

Marshall Barton

Mary said:
The following code I placed in the "after update" event, but it's not doing
what I want it to do. Basically, I want those fields that do not have data
typed in them to turn the color of the form which is light green, & if data
is entered the field to be a white backcolor.
Thanks for your help.

Private Sub TermDate_AfterUpdate()
If IsNull(Me.TermDate) Or Me.TermDate = "" Then
Me.[TermDate].BackColor = 13434828 ' change to light green
Else
Me.[TermDate].BackColor = 16777215 ' change to white
End If
End Sub


By itself, the code looks ok. What is happening?

An alternatinve to using a code procedure for this would be
to use Conditional Formatting (View menu)
 
M

Mary A Perez

Well, it's changing all the records to light green in that text box
regardless of entered data or not.
After thinking about it, I want the whole form to color in any blank fields
if no data is entered. Can I do that on the form somehow w/o coding each
field?
Is that what the conditional formatting does?
Thank you

Marshall Barton said:
Mary said:
The following code I placed in the "after update" event, but it's not doing
what I want it to do. Basically, I want those fields that do not have data
typed in them to turn the color of the form which is light green, & if data
is entered the field to be a white backcolor.
Thanks for your help.

Private Sub TermDate_AfterUpdate()
If IsNull(Me.TermDate) Or Me.TermDate = "" Then
Me.[TermDate].BackColor = 13434828 ' change to light green
Else
Me.[TermDate].BackColor = 16777215 ' change to white
End If
End Sub


By itself, the code looks ok. What is happening?

An alternatinve to using a code procedure for this would be
to use Conditional Formatting (View menu)
 
M

Marshall Barton

Ahh ha, "changing all the records" is the critical piece of
information. That implies that you are using a continuous
form and the explanation is that each detail section control
only has one set of properties. So, setting a property
applies to all display copies of the control.

And, Yes, that's what Conditional Formatting is for. The
Value Is and Expression Is options allow you a decent degree
of control over a few of the display type properties of each
record's controls. In this case, I think you want to set
the Expression Is option to Nz([controlname], "") = "" and
select the desired back color for records that satisfy that
condition. You will have to make this setting on eachtext
box control.

If the little color palette does not have the exact color
green you are using for the form, either find a compromise
color or use code to change the color property setting by
going through the FormatCondition object (see Help for
details).
--
Marsh
MVP [MS Access]

Well, it's changing all the records to light green in that text box
regardless of entered data or not.
After thinking about it, I want the whole form to color in any blank fields
if no data is entered. Can I do that on the form somehow w/o coding each
field?
Is that what the conditional formatting does?

Mary said:
The following code I placed in the "after update" event, but it's not doing
what I want it to do. Basically, I want those fields that do not have data
typed in them to turn the color of the form which is light green, & if data
is entered the field to be a white backcolor.
Thanks for your help.

Private Sub TermDate_AfterUpdate()
If IsNull(Me.TermDate) Or Me.TermDate = "" Then
Me.[TermDate].BackColor = 13434828 ' change to light green
Else
Me.[TermDate].BackColor = 16777215 ' change to white
End If
End Sub
Marshall Barton said:
By itself, the code looks ok. What is happening?

An alternatinve to using a code procedure for this would be
to use Conditional Formatting (View menu)
 
M

Mary A Perez

I just wanted to let you know how wonderful you are!!! I didn't get a chance
until today to work with the conditional formatting & the expression you gave
me & it works wonderfully.
You are the best!
Happy Holidays!

Marshall Barton said:
Ahh ha, "changing all the records" is the critical piece of
information. That implies that you are using a continuous
form and the explanation is that each detail section control
only has one set of properties. So, setting a property
applies to all display copies of the control.

And, Yes, that's what Conditional Formatting is for. The
Value Is and Expression Is options allow you a decent degree
of control over a few of the display type properties of each
record's controls. In this case, I think you want to set
the Expression Is option to Nz([controlname], "") = "" and
select the desired back color for records that satisfy that
condition. You will have to make this setting on eachtext
box control.

If the little color palette does not have the exact color
green you are using for the form, either find a compromise
color or use code to change the color property setting by
going through the FormatCondition object (see Help for
details).
--
Marsh
MVP [MS Access]

Well, it's changing all the records to light green in that text box
regardless of entered data or not.
After thinking about it, I want the whole form to color in any blank fields
if no data is entered. Can I do that on the form somehow w/o coding each
field?
Is that what the conditional formatting does?

Mary A Perez wrote:
The following code I placed in the "after update" event, but it's not doing
what I want it to do. Basically, I want those fields that do not have data
typed in them to turn the color of the form which is light green, & if data
is entered the field to be a white backcolor.
Thanks for your help.

Private Sub TermDate_AfterUpdate()
If IsNull(Me.TermDate) Or Me.TermDate = "" Then
Me.[TermDate].BackColor = 13434828 ' change to light green
Else
Me.[TermDate].BackColor = 16777215 ' change to white
End If
End Sub
Marshall Barton said:
By itself, the code looks ok. What is happening?

An alternatinve to using a code procedure for this would be
to use Conditional Formatting (View menu)
 
D

David C. Holley

Or you can try this

add "required" to the tag property of the fields on a form that are
required. If you've got another value in there, separate them with
semicolons and update any other code that looks at that property to use
astericks. The advantage to do this over ConditionalFormating is that
its alot easier to change the highlight colors.

Sub Form_BeforeUpdate(Cancel As Integer)

If validateFields(Me) <> 0 then
MsgBox("The highlighted fields are required. Or whatever.")
Cancel = True
end if

End sub

Function validateFields(frmFormName As Form)

Dim control As control
Dim fieldCount As Integer

fieldCount = 0

For Each control In frmFormName.Controls
If control.Tag Like "*" & "required" & "*" Then
control.ForeColor = 0
control.BackColor = 16777215
End If
Next

For Each control In frmFormName.Controls
If control.Tag Like "*" & "required" & "*" Then
If IsNull(control.Value) Or control.Value = "" Then
control.ForeColor = 16777215
control.BackColor = 255
fieldCount = fieldCount + 1
End If
End If
Next

validateFields = fieldCount

End Function
I just wanted to let you know how wonderful you are!!! I didn't get a chance
until today to work with the conditional formatting & the expression you gave
me & it works wonderfully.
You are the best!
Happy Holidays!

:

Ahh ha, "changing all the records" is the critical piece of
information. That implies that you are using a continuous
form and the explanation is that each detail section control
only has one set of properties. So, setting a property
applies to all display copies of the control.

And, Yes, that's what Conditional Formatting is for. The
Value Is and Expression Is options allow you a decent degree
of control over a few of the display type properties of each
record's controls. In this case, I think you want to set
the Expression Is option to Nz([controlname], "") = "" and
select the desired back color for records that satisfy that
condition. You will have to make this setting on eachtext
box control.

If the little color palette does not have the exact color
green you are using for the form, either find a compromise
color or use code to change the color property setting by
going through the FormatCondition object (see Help for
details).
--
Marsh
MVP [MS Access]

Well, it's changing all the records to light green in that text box
regardless of entered data or not.
After thinking about it, I want the whole form to color in any blank fields
if no data is entered. Can I do that on the form somehow w/o coding each
field?
Is that what the conditional formatting does?



Mary A Perez wrote:

The following code I placed in the "after update" event, but it's not doing
what I want it to do. Basically, I want those fields that do not have data
typed in them to turn the color of the form which is light green, & if data
is entered the field to be a white backcolor.
Thanks for your help.

Private Sub TermDate_AfterUpdate()
If IsNull(Me.TermDate) Or Me.TermDate = "" Then
Me.[TermDate].BackColor = 13434828 ' change to light green
Else
Me.[TermDate].BackColor = 16777215 ' change to white
End If
End Sub


:

By itself, the code looks ok. What is happening?

An alternatinve to using a code procedure for this would be
to use Conditional Formatting (View menu)
 
M

Marshall Barton

David, that works fine on a form in Single view, but Mary's
form is in Continuous view so all rows show the colors
assigned to the current record in your procedure.
--
Marsh
MVP [MS Access]

Or you can try this

add "required" to the tag property of the fields on a form that are
required. If you've got another value in there, separate them with
semicolons and update any other code that looks at that property to use
astericks. The advantage to do this over ConditionalFormating is that
its alot easier to change the highlight colors.

Sub Form_BeforeUpdate(Cancel As Integer)

If validateFields(Me) <> 0 then
MsgBox("The highlighted fields are required. Or whatever.")
Cancel = True
end if

End sub

Function validateFields(frmFormName As Form)

Dim control As control
Dim fieldCount As Integer

fieldCount = 0

For Each control In frmFormName.Controls
If control.Tag Like "*" & "required" & "*" Then
control.ForeColor = 0
control.BackColor = 16777215
End If
Next

For Each control In frmFormName.Controls
If control.Tag Like "*" & "required" & "*" Then
If IsNull(control.Value) Or control.Value = "" Then
control.ForeColor = 16777215
control.BackColor = 255
fieldCount = fieldCount + 1
End If
End If
Next

validateFields = fieldCount

End Function
I just wanted to let you know how wonderful you are!!! I didn't get a chance
until today to work with the conditional formatting & the expression you gave
me & it works wonderfully.
You are the best!
Happy Holidays!

:

Ahh ha, "changing all the records" is the critical piece of
information. That implies that you are using a continuous
form and the explanation is that each detail section control
only has one set of properties. So, setting a property
applies to all display copies of the control.

And, Yes, that's what Conditional Formatting is for. The
Value Is and Expression Is options allow you a decent degree
of control over a few of the display type properties of each
record's controls. In this case, I think you want to set
the Expression Is option to Nz([controlname], "") = "" and
select the desired back color for records that satisfy that
condition. You will have to make this setting on eachtext
box control.

If the little color palette does not have the exact color
green you are using for the form, either find a compromise
color or use code to change the color property setting by
going through the FormatCondition object (see Help for
details).
--
Marsh
MVP [MS Access]


Mary A Perez wrote:

Well, it's changing all the records to light green in that text box
regardless of entered data or not.
After thinking about it, I want the whole form to color in any blank fields
if no data is entered. Can I do that on the form somehow w/o coding each
field?
Is that what the conditional formatting does?



Mary A Perez wrote:

The following code I placed in the "after update" event, but it's not doing
what I want it to do. Basically, I want those fields that do not have data
typed in them to turn the color of the form which is light green, & if data
is entered the field to be a white backcolor.
Thanks for your help.

Private Sub TermDate_AfterUpdate()
If IsNull(Me.TermDate) Or Me.TermDate = "" Then
Me.[TermDate].BackColor = 13434828 ' change to light green
Else
Me.[TermDate].BackColor = 16777215 ' change to white
End If
End Sub


:

By itself, the code looks ok. What is happening?

An alternatinve to using a code procedure for this would be
to use Conditional Formatting (View menu)
 

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