Change txtBox font size depending on contents (1 Viewer)

i4004

New member
Local time
Today, 10:31
Joined
Feb 5, 2010
Messages
6
Any idea if it is possible to change the font size of a report text box according to it contents - in this case text which is either A or C?

Conditional formatting does not appear to do more than change the style of font - I cannot see a text size option.

Events do not appear to include 'OnOpen' etc.
 

Mr. B

"Doctor Access"
Local time
Today, 04:31
Joined
May 20, 2009
Messages
1,932
You will need to use the OnFormat event of each section of your report. Using that event, you can use VBA to change any property of your text box, including the font size, color, etc.
 

vbaInet

AWF VIP
Local time
Today, 10:31
Joined
Jan 22, 2010
Messages
26,374
If you set the "Can Grow" property of the controls they should automatically become wider to fit text when printed.
 

i4004

New member
Local time
Today, 10:31
Joined
Feb 5, 2010
Messages
6
You will need to use the OnFormat event of each section of your report. Using that event, you can use VBA to change any property of your text box, including the font size, color, etc.

Thanks - I have used the OnFormat event of the detail section with an embedded macro. However, I could not find (nor in VBA) a font size property.

Instead I have used two different txtBoxes, one with large font, one with small. I have then used conditions in the macros to find which one to make visible and which invisible using the SetProperty action. Rather a bodge but it works as required.

However, am I missing the route to the font size? In vba I tried the 'docmd.setproperty' but, as in the macro, could only see 'visible' as an option to use.
 

Rich

Registered User.
Local time
Today, 10:31
Joined
Aug 26, 2008
Messages
2,898
If you set the "Can Grow" property of the controls they should automatically become wider to fit text when printed.
CanGrow only affects the length of the textbox surely?
 

vbaInet

AWF VIP
Local time
Today, 10:31
Joined
Jan 22, 2010
Messages
26,374
Correct Rich. I was actually rather sleepy when I wrote that :)

An idea would be (using On Format) event check the current number of characters and based on that increase or decrease accordingly using the FontSize property. You would test manually to see the maximum number of characters that will fit based on the largest font size you want to use.
 

Mr. B

"Doctor Access"
Local time
Today, 04:31
Joined
May 20, 2009
Messages
1,932
i4004,

Just so you will know for future reference, there are properties that can be used with controls and sections of reports that for some unknown (at least to me) reason are not displayed in the intellisence lists for the selected control or section when writing VBA code.

From the VBA help file about "Font Name Property":

Code:
Private Sub Detail_Format(Cancel As Integer, _        FormatCount As Integer)    Dim rpt as Report    Dim strMessage As String    Dim intHorSize As Integer, intVerSize As Integer    Set rpt = Me    strMessage = "DisplayMessage"    With rpt        'Set scale to pixels, and set FontName and        'FontSize properties.        .ScaleMode = 3        .[B]FontName[/B] = "Courier"        .FontSize = 24    End With    ' Horizontal width.    intHorSize = Rpt.TextWidth(strMessage)    ' Vertical height.    intVerSize = Rpt.TextHeight(strMessage)    ' Calculate location of text to be displayed.    Rpt.CurrentX = (Rpt.ScaleWidth/2) - (intHorSize/2)    Rpt.CurrentY = (Rpt.ScaleHeight/2) - (intVerSize/2)    ' Print text on Report object.    Rpt.Print strMessageEnd Sub

Hopefully from this example you can get an idea of just how much control you actuall can have over the properties of a text box and/or other controls when using VBA.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 10:31
Joined
Sep 12, 2006
Messages
15,709
intellisense wont show you all the properties but this

ProductField.Properties("fontweight") = 700

is the correct sort of syntax


--------------
this sort of thing should show you all the available properties

dim prp as property

For Each prp In anyfield.Properties
msgbox(prp.name)
Next prp
 

Users who are viewing this thread

Top Bottom