Ted said:
that was somewhat easier to follow (relative newbie over here) but here's a
snag thhat i found; although the field txtCurkey is recognized by VBA when i
add it to the VBA code i'm writing in On Current event section, the name (i
guess that) my PK's called "PrimaryKey" (to judge from its appearance in the
Index name column of the table's) is not and VBA chokes on it. what to do?
The field name is the name of the **field** in the table's
design view, not the name of an index. You may or may not
have a field named PrimaryKey and you may or may not have an
index named PrimaryKey, but they are different things.
Are you sure you need so many fields in the primary key
index? Wouldn't the irb_number field be sufficient? At
least you should be aware that the lastname, firstname and
mi fields will **NOT** help identify a unique record, any
number of people can have the same name. So, at least you
should remove those from the PK index's field list. Then
rethink your idea of primary key to make sure you aren't
going to run into a wall somewhere down the road.
does your explanation only hold for the case when there's
just one field that's been designated a PK; in my case there
are 5 fields!!??
What we're looking for here is the field or fields that
uniquely identify a record. We need this so that the
conditional formatting will only be applied to one record.
If there are multiple fields required to uniquely identify a
record, then you will need a text box in the header section
for each field and a line of code to assign each value to
the text boxes.
Me.txtCurKey1 = Me.nameofPKfield1
Me.txtCurKey2 = Me.nameofPKfield2
. . .
The CF expression will then be more like this:
[nameofPKfield1] = [txtCurKey1] And [nameofPKfield2] =
[txtCurKey2] And . . .
--
Marsh
MVP [MS Access]
Ted wrote:
my pk consists of lastname, firstname, mi, medrecord, irb_number. can you
flesh out a little more what you're suggestion would look like. i don't know
if this really matters all that much, but my datasheet form is a sub-form of
a main form. the main one's called "DataSheet View of Screen" and the
subFrm's called "Screening Log DS View". the form header of the subForm's
holds nothing but labels with the controls' names.
Marshall Barton said:
Look at the subform's Form object in design view. Make sure
the Form Header section exists (View menu). Create a text
box named txtCurKey in the header section.
Display the Form's property sheet, select the OnCurrent
property and click on the [...] button at the right side of
the property. When the code window appears, add a line of
code at the cursor:
Me.txtCurKey = Me.nameofPKfield
Now, go back to the form design screen and select the
lastname text box. Then use the Format - Conditional
Formatting menu item to open the CF window. Select the
Expression Is option in the drop down box and enter the
expression:
[nameofPKfield] = [txtCurKey]
and select your special fore and back ground colors.
Test it to make sure the last name text box works the way
you want it. When it does, repeat the CF settings for the
other text boxes.
Ted wrote:
i have a form (that uses a query as its record source) in datasheet view. i
would like to be able to change the colors (fore and/or background) of the
controls on it subject to the condition the record pointer is on a particular
record. if you make a change to a controls color properties, when the data is
viewed in this form, it applies to everything the user sees not just the
record the pointer's on. i don't know if it makes a difference, but records
on the form are non-editable, non-deletable and records may not be added
using this particular datasheet view.
:
The only way I know of that can do this in datasheet view is
Conditional Formatting (Format menu).
To highlight the current record, use the form's Current
event to set the record's PK field to a text box in the
form's header section. Then use this text box in the
condition for each bound control in the detail section.