conditional formatting - new record

J

John

Does anybody know how to set conditional formatting for a
new record? I've got a continuous form and I want the
background color to be different for just the new record
line.

Thanks!

John
 
A

AJ Raiber

John,

Are you saying that you want a new record input screen to
look different than a standard screen, or are you saying
you want a portion of the screen to look different?

AJ
 
G

Guest

All of this will take place on the same screen, on a
continuous form. I just want the back ground colors of
the controls on the 'new record' line to be a different
color than the records which are already entered into the
database.

I'm thinking that this would be some sort of conditional
formatting driven off of the "on open" and "after insert"
events.

Does that make sense?

Thanks. John
 
A

AJ Raiber

John,

I think this will work for you. All of you MVP's out
there, please help check this and see what you think. I
am one of those people who know just enough to be really
dangerous, but I am not sure if this will work in a
continuous form. In a single record form I would be sure.

****************************************************
Private Sub Form_Current()

If Me.NewRecord = True Then
Me.DatasheetBackColor = X '(X is your color number)
End If

End Sub
*****************************************************

Private Sub Form_update()

If Me.NewRecord = True Then
Me.DatasheetBackColor = Y '(Y is the color number)
End If

End Sub

******************************************************

I believe this should work for you. Like I said, I do not
deal with continuous forms much, so I don't know if that
will have an effect or not.

MVPs, please help here as well.

HTH

AJ Raiber
 
A

Amadeo Cayuelas

You can use some VB code to do this. For instance...

Private Sub Form_Current()
Const lngNewRecColour as Long = <ColourNumber>
Const lngStdRecColour as Long = <OtherColourNumber>

If Me.NewRecord Then
Me.<FieldName1>.BackColor = lngNewRecColour
Me.<FieldName2>.BackColor = lngNewRecColour
....
Me.<FieldNameN>.BackColor = lngNewRecColour
Else
Me.<FieldName1>.BackColor = lngStdRecColour
Me.<FieldName2>.BackColor = lngStdRecColour
....
Me.<FieldNameN>.BackColor = lngStdRecColour
End If
End Sub

**Replace <ColourNumber> and <OtherColourNumber> with valid numbers of
colour to test this code.
See help on "BackColor"

Amadeo, from Barcelona (Spain)
 
J

John

Thanks for your help, but I could not get this to work
with a continuous form.
Anybody else have any ideas?

Thanks.
Jeremy
 
C

Cheryl Fischer

John,

I interpret your question to mean that you always want to see the NewRecord
row in a different color regardless of whether you have actually clicked on
that row. As you have probably seen from AJ's code, you can reset the
backcolor of the *entire* detail section of a continuous form using code
similar to the following (once you have clicked into the new record, thereby
changing the form's NewRecord property to true):

If Me.NewRecord = True Then
Me.Detail.BackColor = 65535
End If

This is the expected behavior of a continuous form.

From time to time, there have been questions posted about the new record
line in continuous forms or datasheet view, most commonly moving the new
record line to the top of the form. The answer to that one is: this is
"by design" and cannot be changed. I suspect that the answer is the same
for making the new record line appear with a different back or fore color.

One possible work-around is to use a main form and two subforms. The first
subform will show only existing records; it will have its AllowAdditions
property set to 'No' and its Detail section's backcolor set to your
normal/desired backcolor. The second subform will be used only to add
records; its DataEntry property will be set to 'Yes' and its detail
backcolor or controls backcolor and/or forecolor can be set to your desired
"highlight" colors. These subforms can be positioned on your main form so
that they appear to reasonably approximate a single form.

hth,
 

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