Highlight current record

R

RobGMiller

Access 2003.

Need to highlight the current record on a subform setup in continuous forms
view.

I found a way to do it a long time ago by setting the value of a control on
the main or parent form to the value of a LineNumber control on the current
record of the subform which is always a unique value. This is done in the
OnCurrent event of the subform. As you move through the records the OnCurrent
event fires and updates the Parentform control.

In Conditional formatting for a field that never gets the focus I change the
background color if Expression Is: Me!LineNumber = ParentForm!LineNumber or
somethign to that effect.

This worked perfectly until recently. If you clicked on a record or move to
it using the cursor(arrow) keys the background would change color. Now the
background color will only change color if a record is updated due to a
change in value of one of its controls.

I've made many changes to this application since this technique last worked.
None of which seems related to this type of thing. I though someone might
have some insight as to how the Conditional Formatting works. i.e. What
triggers the formatting of all the controls on a record when the record or
one of its controls gets the focus.

I am sure that no background code runs as different records get the focus
unless something is changed. I've tried repaint instead of refresh which was
used after the value of the ParentForm control is set from the OnCurrent
Event of the subform. Requery looses the focus alltogether so its useless in
this case.




RobGMiller
 
J

Jeanette Cunningham

Rob,
it sounds as if your most recent changes to this form or its query/table
have intereferred with the technique working.
Go back to one of your backups where this form did work for conditional
formatting and see if you can find what is different in the latest version
of your database.


Jeanette Cunningham -- Melbourne Victoria Australia
 
R

RobGMiller

Thanks for that Jeanette,

There have been so many changes since the last working version that its
worth the trouble of attemting to understand the process so that I can avoid
trying to iliminate what might have happened that caused this failure.

I suppose that one could argue that whatever functionality has been added
that caused the breakdown is necessary and the time required to find a way of
doing it that does not interfere with this process might very well take
longer than understanding the process. One might also argue that it is likely
necessary to understand the highlight process well enough to make the new
functionality work withought disrupting the record highlight process.
 
J

Jeanette Cunningham

Rob,
I noticed that you used the expression
Me!LineNumber = ParentForm!LineNumber

Instead of ParentForm!LineNumber
use
Parent!LineNumber

As an aid to debug it, try code like this on the form's On Current event

Debug.Print "Parent!LineNumber: " & Parent!LineNumber
Debug.Print "Me!LineNumber: " & Me!LineNumber

Run the form, then go Ctl + G to open the immediate window and see what
values access found for the line number.


Jeanette Cunningham -- Melbourne Victoria Australia
 
R

RobGMiller

If I view the value of Forms!ParentForm!LineNumber immediatly after setting
it in the OnCurrent event as you suggest it shows the correct value for the
current record.

If the conditional formatting of the controls on the current record occurs
after the OnCurrent event is done then the correct value should be returned.

What might prevent the conditionnal formatting process to run in a normal
sequence?

What is the normal sequence of events that occur as a control on a record
gets the focus in a subform in continuous forms view?
 
J

Jeanette Cunningham

Rob,
in the normal sequence of events, there is only one *real* copy of each
control on a continuous form.
I'm not really sure how conditional formatting deals with this.
Some questions:
1. As you are using Forms!ParentForm!LineNumber, does this mean that the
subform is on a different form from Forms!ParentForm!LineNumber ?
Normally with a parent and child - form/subform setup you refer to the
control on the parent form as Parent.ControlName when the code is running in
the subform.
If not, are you sure that Forms!ParentForm!LineNumber is open at the same
time as the subform.

2. How do you get the value for Forms!ParentForm!LineNumber - does it come
from a field in this form's recordsource?

3. Which field in the subform's recordsource is related one to many to the
parent form's recordsource?

I am more familiar with setting conditional formatting using the value of a
control - if the field value is <0, then make the text box have a red
background, if not, then make it have a white background.
You are using -If Expression - maybe someone else with experience with
exactly this can jump in with the answer.


Jeanette Cunningham -- Melbourne Victoria Australia
 
R

RobGMiller

Thanks for your time Jeanette,

I think the subform is opened prior to the parent form but the
SubForm.OnCurrent even must fire after the parent form is opened as the first
record gets the focus.

The technique is comparing the value of a control(LineNumber) on the current
record to the value of a different control located elsewhere (LN) containing
a number. If the value is the same, it formats the background to a different
color.

The value of LN has to be changed before the controls on the current record
are updated using the conditional format process. The OnCurrent event must
fire prior to the conditional format process since this was working before.

The subform is in a SubForm container on a different form as in:
Forms!ParentForm!SubformContainer.Form
LN is updated from the subform OnCurrent even as the focus moves to the next
record as in:
Forms!ParentForm!LN = Me!LineNumber
As I mentioned before, Forms!ParentForm!LN does get changed as soon as the
Forms!ParentForm!LN = Me!LineNumber action is taken in the OnCurrent event.

I remember the first thing I tried when I came up with this technique was to
set the LN.ControlSource to
=Forms!ParentForm!SubformContainer.Form!LineNumber but that did not work.
However setting the value of LN with the OnCurrent event did until recently.
 
R

RobGMiller

Thanks for that Jeanette,

The only difference between what that page suggests and what I am doing is
that OnCurrent sets the value of a control that is located on the Subform as
opposed to its parent.

However, it does work.

I am guessing that the Subform change is more immediate than its parent. Not
sure why I didn't put it there in the first place. I suppose, when something
works you leave it until it breaks....

Thanks again for your time.
 

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