Connecting Tech Pros Worldwide Forums | Help | Site Map

Changing Formatting of All Controls in Current Record

DBQueen
Guest
 
Posts: n/a
#1: Nov 12 '05
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




Bas Cost Budde
Guest
 
Posts: n/a
#2: Nov 12 '05

re: Changing Formatting of All Controls in Current Record


DBQueen wrote:
[color=blue]
> 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?)[/color]

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

Andi Plotsky
Guest
 
Posts: n/a
#3: Nov 12 '05

re: Changing Formatting of All Controls in Current Record


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" <bas@heuveltop.org> wrote in message
news:bvnor0$od5$1@news2.solcon.nl...[color=blue]
> DBQueen wrote:
>[color=green]
> > I have a subform which is in Continuous Forms view.
> >
> > I want all of the controls in whatever is the CURRENT record to have[/color][/color]
it's[color=blue][color=green]
> > data bolded on the screen. (Question #1: Is there a SIMPLE way to refer[/color][/color]
to[color=blue][color=green]
> > the Current Record?)[/color]
>
> 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
>[/color]


Steve Jorgensen
Guest
 
Posts: n/a
#4: Nov 12 '05

re: Changing Formatting of All Controls in Current Record


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" <irisinfo@bellsouth.net> wrote:
[color=blue]
>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
>
>[/color]

Andi Plotsky
Guest
 
Posts: n/a
#5: Nov 12 '05

re: Changing Formatting of All Controls in Current Record


Thanks, Steve. I'll give it a try!


Andi Plotsky


"Steve Jorgensen" <nospam@nospam.nospam> wrote in message
news:tgjv1018nq91mp0eajadbf3hq9jo4u5h0l@4ax.com...[color=blue]
> 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[/color]
the[color=blue]
> currently selected row to format. So, here's the trick...
>
> You need 2 invisible controls on the form, one bound to the record's[/color]
primary[color=blue]
> key column, and one unbound that will hold a copy of the key for the[/color]
current[color=blue]
> 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[/color]
for[color=blue]
> 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[/color]
bold,[color=blue]
> 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[/color]
about[color=blue]
> its formatting, that will fail when you try to apply the change - this[/color]
problem[color=blue]
> occurs more often than not.
>
> So, I recommend writing a procedure that takes a control as its argument[/color]
and[color=blue]
> adds a set of Conditional Formatting attributes appropriately. In the[/color]
form's[color=blue]
> Open event handler, call the function once for each control in question,[/color]
so[color=blue]
> conditional formatting is set up. Now, to change the conditional[/color]
formatting,[color=blue]
> you just change 1 or 2 lines in the procedure, and to change which[/color]
controls it[color=blue]
> 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[/color]
code.[color=blue]
>
> On Tue, 3 Feb 2004 01:34:52 -0500, "DBQueen" <irisinfo@bellsouth.net>[/color]
wrote:[color=blue]
>[color=green]
> >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[/color][/color]
record[color=blue][color=green]
> >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[/color][/color]
to[color=blue][color=green]
> >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[/color][/color]
error"[color=blue][color=green]
> > SampleID.FontWeight = 900 '900 =bold fontweight
> > SubjName.FontWeight = 900
> > TimeOfSample.FontWeight = 900
> >Next ocontrol
> >
> >Any help would be greatly appreciated.
> >
> >Thanks!
> >
> >Andi
> >
> >[/color]
>[/color]


Closed Thread


Similar Microsoft Access / VBA bytes