472,143 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

Changing Formatting of All Controls in Current Record

I have a subform which is in Continuous Forms view.

I have added a button to the bottom of the page to move to the next record
using the button wizard (result: DoCmd.GoToRecord , , acNext).

I want all of the controls in whatever is the CURRENT record to have it's
data bolded on the screen. (Question #1: Is there a SIMPLE way to refer to
the Current Record?)

I've been trying to use a Bookmark to specify the current record, but it
doesn't seem to work. I keep either getting error msgs or ALL records'
controls are bolded.

Form_Current:

Dim ocontrol As control
Dim rst As DAO.Recordset
Dim varBookmark As Variant

SampleID.FontWeight = 400 '400=Normal fontweight
SubjName.FontWeight = 400
TimeOfSample.FontWeight = 400

Set rst = Me.RecordsetClone
varBookmark = Me.Bookmark

For Each ocontrol In varBookmark 'this gives me an "Object Required error"
SampleID.FontWeight = 900 '900 =bold fontweight
SubjName.FontWeight = 900
TimeOfSample.FontWeight = 900
Next ocontrol

Any help would be greatly appreciated.

Thanks!

Andi

Nov 12 '05 #1
4 3964
DBQueen wrote:
I have a subform which is in Continuous Forms view.

I want all of the controls in whatever is the CURRENT record to have it's
data bolded on the screen. (Question #1: Is there a SIMPLE way to refer to
the Current Record?)


It is implicit. You can refer to the current record's values by
addressing the fields (me!yourfield).

You cannot address the *controls* on the form for the current record
only, because the controls are defined only once.
--
Bas Cost Budde
http://www.heuveltop.nl/BasCB

Nov 12 '05 #2
My first thought was to just use Me!....However, ALL of the records on the
form change to a bold font, not just the current record which has the focus.
That is because ME refers to the current form, not an individual record on
the form. Remember, I'm using Continuous Forms view. Therefore, I think
using Recordsets and/or Bookmarks is necessary, but I'm not sure how to get
it to work correctly.

Andi

"Bas Cost Budde" <ba*@heuveltop.org> wrote in message
news:bv**********@news2.solcon.nl...
DBQueen wrote:
I have a subform which is in Continuous Forms view.

I want all of the controls in whatever is the CURRENT record to have it's data bolded on the screen. (Question #1: Is there a SIMPLE way to refer to the Current Record?)


It is implicit. You can refer to the current record's values by
addressing the fields (me!yourfield).

You cannot address the *controls* on the form for the current record
only, because the controls are defined only once.
--
Bas Cost Budde
http://www.heuveltop.nl/BasCB

Nov 12 '05 #3
The only way to format data in some rows different than others is to use
Conditional Formatting, but there's no built-in way to identify what is the
currently selected row to format. So, here's the trick...

You need 2 invisible controls on the form, one bound to the record's primary
key column, and one unbound that will hold a copy of the key for the current
row (e.g. txtFooID and txtDooIDCur). Next, add a Current event handler to
your form that copies the key value to the unbound control (e.g.
Me!txtFooIDCur = me!txtFooID). Finally, set the conditional formatting for
each control on the form to be bold when Me!txtFooIDCur = me!txtFooID.

Note that this is a bit of a maintenance hassle since, if you decide later
that you want the current row to be, say, a different color rather than bold,
you have to edit the custom formatting for each control individually.
Technically, you can highlight all the controls, and change the custom
formatting for all at once, but if any control has something different about
its formatting, that will fail when you try to apply the change - this problem
occurs more often than not.

So, I recommend writing a procedure that takes a control as its argument and
adds a set of Conditional Formatting attributes appropriately. In the form's
Open event handler, call the function once for each control in question, so
conditional formatting is set up. Now, to change the conditional formatting,
you just change 1 or 2 lines in the procedure, and to change which controls it
applies to, you just edit the code block in Form_Open with the sequence of
calls to the procedure.

See the Help files for more on how to set Conditional Formatting from code.

On Tue, 3 Feb 2004 01:34:52 -0500, "DBQueen" <ir******@bellsouth.net> wrote:
I have a subform which is in Continuous Forms view.

I have added a button to the bottom of the page to move to the next record
using the button wizard (result: DoCmd.GoToRecord , , acNext).

I want all of the controls in whatever is the CURRENT record to have it's
data bolded on the screen. (Question #1: Is there a SIMPLE way to refer to
the Current Record?)

I've been trying to use a Bookmark to specify the current record, but it
doesn't seem to work. I keep either getting error msgs or ALL records'
controls are bolded.

Form_Current:

Dim ocontrol As control
Dim rst As DAO.Recordset
Dim varBookmark As Variant

SampleID.FontWeight = 400 '400=Normal fontweight
SubjName.FontWeight = 400
TimeOfSample.FontWeight = 400

Set rst = Me.RecordsetClone
varBookmark = Me.Bookmark

For Each ocontrol In varBookmark 'this gives me an "Object Required error"
SampleID.FontWeight = 900 '900 =bold fontweight
SubjName.FontWeight = 900
TimeOfSample.FontWeight = 900
Next ocontrol

Any help would be greatly appreciated.

Thanks!

Andi


Nov 12 '05 #4
Thanks, Steve. I'll give it a try!
Andi Plotsky
"Steve Jorgensen" <no****@nospam.nospam> wrote in message
news:tg********************************@4ax.com...
The only way to format data in some rows different than others is to use
Conditional Formatting, but there's no built-in way to identify what is the currently selected row to format. So, here's the trick...

You need 2 invisible controls on the form, one bound to the record's primary key column, and one unbound that will hold a copy of the key for the current row (e.g. txtFooID and txtDooIDCur). Next, add a Current event handler to
your form that copies the key value to the unbound control (e.g.
Me!txtFooIDCur = me!txtFooID). Finally, set the conditional formatting for each control on the form to be bold when Me!txtFooIDCur = me!txtFooID.

Note that this is a bit of a maintenance hassle since, if you decide later
that you want the current row to be, say, a different color rather than bold, you have to edit the custom formatting for each control individually.
Technically, you can highlight all the controls, and change the custom
formatting for all at once, but if any control has something different about its formatting, that will fail when you try to apply the change - this problem occurs more often than not.

So, I recommend writing a procedure that takes a control as its argument and adds a set of Conditional Formatting attributes appropriately. In the form's Open event handler, call the function once for each control in question, so conditional formatting is set up. Now, to change the conditional formatting, you just change 1 or 2 lines in the procedure, and to change which controls it applies to, you just edit the code block in Form_Open with the sequence of
calls to the procedure.

See the Help files for more on how to set Conditional Formatting from code.
On Tue, 3 Feb 2004 01:34:52 -0500, "DBQueen" <ir******@bellsouth.net> wrote:
I have a subform which is in Continuous Forms view.

I have added a button to the bottom of the page to move to the next recordusing the button wizard (result: DoCmd.GoToRecord , , acNext).

I want all of the controls in whatever is the CURRENT record to have it's
data bolded on the screen. (Question #1: Is there a SIMPLE way to refer tothe Current Record?)

I've been trying to use a Bookmark to specify the current record, but it
doesn't seem to work. I keep either getting error msgs or ALL records'
controls are bolded.

Form_Current:

Dim ocontrol As control
Dim rst As DAO.Recordset
Dim varBookmark As Variant

SampleID.FontWeight = 400 '400=Normal fontweight
SubjName.FontWeight = 400
TimeOfSample.FontWeight = 400

Set rst = Me.RecordsetClone
varBookmark = Me.Bookmark

For Each ocontrol In varBookmark 'this gives me an "Object Required error" SampleID.FontWeight = 900 '900 =bold fontweight
SubjName.FontWeight = 900
TimeOfSample.FontWeight = 900
Next ocontrol

Any help would be greatly appreciated.

Thanks!

Andi

Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Prakash Wadhwani | last post: by
2 posts views Thread by Paul Mendez | last post: by
reply views Thread by Cato Lommerud | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.