Bold report column based on month

C

Chuck

I have a report with a column for each month. (Jan, Feb, Mar...)
I'd like to bold the data in the column that the report is run for.
I placed this code in the on Format event of the report to test, the code is
executing ok but the columns end up all in normal weight.
m = DatePart("m", dt)
Select Case m
Case 1
Me.Jan.FontWeight = vbBold
Me.Feb.FontWeight = vbNormal
Me.Mar.FontWeight = vbNormal
Me.Apr.FontWeight = vbNormal
Me.May.FontWeight = vbNormal
Me.Jun.FontWeight = vbNormal
Me.Jul.FontWeight = vbNormal
Me.Aug.FontWeight = vbNormal
Me.Sep.FontWeight = vbNormal
Me.Oct.FontWeight = vbNormal
Me.Nov.FontWeight = vbNormal
Me.Dec.FontWeight = vbNormal
Case 2
Me.Jan.FontWeight = vbNormal
Me.Feb.FontWeight = vbBold
Me.Mar.FontWeight = vbNormal
Me.Apr.FontWeight = vbNormal
Me.May.FontWeight = vbNormal
Me.Jun.FontWeight = vbNormal
Me.Jul.FontWeight = vbNormal
Me.Aug.FontWeight = vbNormal
Me.Sep.FontWeight = vbNormal
Me.Oct.FontWeight = vbNormal
Me.Nov.FontWeight = vbNormal
Me.Dec.FontWeight = vbNormal
End Select
Any help would be appreciated.
Thanks
 
R

Rob Parker

Hi Chuck,

My version of Access (A2002) does not have a built-in constant named vbBold.
It does have a vbNormal constant, but that's one of the Dir constants.

The simplest way to bold (or not bold) the font in a textbox is as follows:
Me.ControlName.FontBold = True 'or False

You can use the FontWeight property, but you need to assign a numeric value
to it; see the Help file for details.

HTH,

Rob
 
C

Chuck

Thank you Rob, worked great.
Is there a place where the constants are listed?
Chuck
 
J

John Spencer

You might want to revise the code a bit.

Dim strM as String
strM = Format(dt,"mmm")

Me.Jan.Fontbold = "Jan" = strM
Me.Feb.Fontbold = "Feb" = strM
Me.Mar.Fontbold = "Mar" = strM
...
Me.Dec.Fontbold = "Dec" = StrM

That way you need twelve lines of code to flip bolding on and off
instead of 12 cases with 12 lines for each case.

Or
Set all the controls fontbold to False and then set the relevant one to true


Dim strM as String
strM = Format(dt,"mmm")
ME.Jan.Fontbold = False
...
Me.Dec.Fontbold = False

Me.Controls(strM).FontBold = True

Either of those two would be a lot easier to change if you decided you
wanted Italic instead of bold. Or a color change for the font.

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
 
R

Rob Parker

Hi Chuck,

They're listed in the Visual Basic Help file (accessed from the VBA editor -
it's not the Access Help file).

In the Contents tab, expand the Visual Basic Language Reference volume.
Then read, learn and inwardly difgest to yout heart's content ;-)

Rob

Chuck said:
Thank you Rob, worked great.
Is there a place where the constants are listed?
Chuck
<snip>
 

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