Special text formatting in subform

S

Sirocco

Well, it's been a while since my last visit. Anyway, anybody know if you
can highlight a row or field in a subform? I've tried various codes but
nothing works. Conditional formatting is good for formatting the condition
field, but not otherwise. I'd like to format a field in a subform that's
not the condition field, how can I do this? Many thanks in advance.
 
G

Graham Mandeno

The trick is to use conditional formatting to format a textbox in the
background.

Create a textbox named txtCurrent. Make it hidden and put it somewhere out
of the way (it could be in the header or footer).

Create another textbox in the detail section named txtBackGround. Set its
properties as follows:
Visible: Yes
Enabled: No
Locked: Yes
Border Style: Transparent
Special Effect: Flat
Back Style: Normal
Back Color: <whatever colour you want the un-highlighted rows to be>

Don't worry about size and position.

In your Form_Load event, position the textbox and make it fill the detail
section:
With txtBackGround
.Top = 0
.Left = 0
.Width = Me.Width
.Height = Me.Section(acDetail).Height
End With

In Form_Current, load the current record's primary key value into
txtCurrent:
txtCurrent = Me.[primary key field]

Now, select txtBackGround and set its conditional formatting:
Expression is: [txtCurrent]=[primary key field]
and select the desired fill/backcolor
 
M

Marshall Barton

Sirocco said:
Well, it's been a while since my last visit. Anyway, anybody know if you
can highlight a row or field in a subform? I've tried various codes but
nothing works. Conditional formatting is good for formatting the condition
field, but not otherwise. I'd like to format a field in a subform that's
not the condition field, how can I do this?


Use Conditional Formatting's Expression Is: option
 
S

Sirocco

The code you gave me proved to be a starting point for an interesting
strategy. I'll let you know how things turn out. I appreciate your help!


Graham Mandeno said:
The trick is to use conditional formatting to format a textbox in the
background.

Create a textbox named txtCurrent. Make it hidden and put it somewhere out
of the way (it could be in the header or footer).

Create another textbox in the detail section named txtBackGround. Set its
properties as follows:
Visible: Yes
Enabled: No
Locked: Yes
Border Style: Transparent
Special Effect: Flat
Back Style: Normal
Back Color: <whatever colour you want the un-highlighted rows to be>

Don't worry about size and position.

In your Form_Load event, position the textbox and make it fill the detail
section:
With txtBackGround
.Top = 0
.Left = 0
.Width = Me.Width
.Height = Me.Section(acDetail).Height
End With

In Form_Current, load the current record's primary key value into
txtCurrent:
txtCurrent = Me.[primary key field]

Now, select txtBackGround and set its conditional formatting:
Expression is: [txtCurrent]=[primary key field]
and select the desired fill/backcolor

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Sirocco said:
Well, it's been a while since my last visit. Anyway, anybody know if you
can highlight a row or field in a subform? I've tried various codes but
nothing works. Conditional formatting is good for formatting the
condition
field, but not otherwise. I'd like to format a field in a subform that's
not the condition field, how can I do this? Many thanks in advance.
 
S

Sirocco

After playing with this code for a while, I discovered that NONE of the code
is needed, just a text box in the detail section with the conditional
formatting. There's nothing going on with the primary key, I don't know
why you threw that in. This is a VERY useful trick that should be in
everyone's tool box, and that I will continue to use. This may be the
primary purpose of "conditional formatting", to highlight selected rows in
forms. Anyway, thanks for sample code.


Graham Mandeno said:
The trick is to use conditional formatting to format a textbox in the
background.

Create a textbox named txtCurrent. Make it hidden and put it somewhere out
of the way (it could be in the header or footer).

Create another textbox in the detail section named txtBackGround. Set its
properties as follows:
Visible: Yes
Enabled: No
Locked: Yes
Border Style: Transparent
Special Effect: Flat
Back Style: Normal
Back Color: <whatever colour you want the un-highlighted rows to be>

Don't worry about size and position.

In your Form_Load event, position the textbox and make it fill the detail
section:
With txtBackGround
.Top = 0
.Left = 0
.Width = Me.Width
.Height = Me.Section(acDetail).Height
End With

In Form_Current, load the current record's primary key value into
txtCurrent:
txtCurrent = Me.[primary key field]

Now, select txtBackGround and set its conditional formatting:
Expression is: [txtCurrent]=[primary key field]
and select the desired fill/backcolor

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Sirocco said:
Well, it's been a while since my last visit. Anyway, anybody know if you
can highlight a row or field in a subform? I've tried various codes but
nothing works. Conditional formatting is good for formatting the
condition
field, but not otherwise. I'd like to format a field in a subform that's
not the condition field, how can I do this? Many thanks in advance.
 

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