how to change font size when field is too long

S

Sam

While printing name tags from names in a database, a name is occasionally
too long to fit the text box using the prefered font size. How can I sense
overflow and reduce the font size for this particular name tag?

Sam
 
S

Sam

Thanks for the input. This general approach should work well with Courier or
other fixed width fonts. Can we step up the technology so that it will work
with a variety of variable width fonts?

Can we determine the required field width for a given field and recursivelly
decrease the font size until the field can be contained in a fixed width
text box. Turbo Tax does that for example.

Sam


Chuck said:
While printing name tags from names in a database, a name is occasionally
too long to fit the text box using the prefered font size. How can I sense
overflow and reduce the font size for this particular name tag?

Sam

Code in Report module:

Option Compare Database
Dim A, B, C, D As Integer
Option Explicit
_____________________________________________________

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)

A = Len([Text2]) 'Full Name
B = Len([Text3]) 'Street Address
C = Len([Text4]) 'City, State Zip

D = 0
D = IIf((A >= B And B < C And A >= C), A, D)
D = IIf((A >= B And B > C And A > C), A, D)
D = IIf((A >= B And B < C And A < C), C, D)
D = IIf((A < B And B > C And A > C), B, D)
D = IIf((A < B And B < C And A < C), C, D)
D = IIf((A < B And B > C And A < C), B, D)

[Reports]![Avery 8160 Labels]![Text2].FontSize = IIf(D > 30, 9, IIf(D >
25, 10,
11))

[Reports]![Avery 8160 Labels]![Text3].FontSize = IIf(D > 30, 9, IIf(D >
25, 10,
11))

[Reports]![Avery 8160 Labels]![Text4].FontSize = IIf(D > 30, 9, IIf(D >
25, 10,
11))

End Sub
 
D

Duane Hookom

Caution from previous reply
Dim A, B, C, D as Integer
will only Dim D as integer and the others will be variants.

If you want to mess with the font size, always search through
www.lebans.com. I found http://www.lebans.com/makefitsingle.htm which I think
meets your requirements.
--
Duane Hookom
Microsoft Access MVP


Sam said:
Thanks for the input. This general approach should work well with Courier or
other fixed width fonts. Can we step up the technology so that it will work
with a variety of variable width fonts?

Can we determine the required field width for a given field and recursivelly
decrease the font size until the field can be contained in a fixed width
text box. Turbo Tax does that for example.

Sam


Chuck said:
While printing name tags from names in a database, a name is occasionally
too long to fit the text box using the prefered font size. How can I sense
overflow and reduce the font size for this particular name tag?

Sam

Code in Report module:

Option Compare Database
Dim A, B, C, D As Integer
Option Explicit
_____________________________________________________

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)

A = Len([Text2]) 'Full Name
B = Len([Text3]) 'Street Address
C = Len([Text4]) 'City, State Zip

D = 0
D = IIf((A >= B And B < C And A >= C), A, D)
D = IIf((A >= B And B > C And A > C), A, D)
D = IIf((A >= B And B < C And A < C), C, D)
D = IIf((A < B And B > C And A > C), B, D)
D = IIf((A < B And B < C And A < C), C, D)
D = IIf((A < B And B > C And A < C), B, D)

[Reports]![Avery 8160 Labels]![Text2].FontSize = IIf(D > 30, 9, IIf(D >
25, 10,
11))

[Reports]![Avery 8160 Labels]![Text3].FontSize = IIf(D > 30, 9, IIf(D >
25, 10,
11))

[Reports]![Avery 8160 Labels]![Text4].FontSize = IIf(D > 30, 9, IIf(D >
25, 10,
11))

End Sub
 
S

Sam

Duane,

This looks like exactly what I desire. Thanks for the reference!

Sam

Duane Hookom said:
Caution from previous reply
Dim A, B, C, D as Integer
will only Dim D as integer and the others will be variants.

If you want to mess with the font size, always search through
www.lebans.com. I found http://www.lebans.com/makefitsingle.htm which I
think
meets your requirements.
--
Duane Hookom
Microsoft Access MVP


Sam said:
Thanks for the input. This general approach should work well with Courier
or
other fixed width fonts. Can we step up the technology so that it will
work
with a variety of variable width fonts?

Can we determine the required field width for a given field and
recursivelly
decrease the font size until the field can be contained in a fixed width
text box. Turbo Tax does that for example.

Sam


Chuck said:
While printing name tags from names in a database, a name is
occasionally
too long to fit the text box using the prefered font size. How can I
sense
overflow and reduce the font size for this particular name tag?

Sam

Code in Report module:

Option Compare Database
Dim A, B, C, D As Integer
Option Explicit
_____________________________________________________

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)

A = Len([Text2]) 'Full Name
B = Len([Text3]) 'Street Address
C = Len([Text4]) 'City, State Zip

D = 0
D = IIf((A >= B And B < C And A >= C), A, D)
D = IIf((A >= B And B > C And A > C), A, D)
D = IIf((A >= B And B < C And A < C), C, D)
D = IIf((A < B And B > C And A > C), B, D)
D = IIf((A < B And B < C And A < C), C, D)
D = IIf((A < B And B > C And A < C), B, D)

[Reports]![Avery 8160 Labels]![Text2].FontSize = IIf(D > 30, 9, IIf(D >
25, 10,
11))

[Reports]![Avery 8160 Labels]![Text3].FontSize = IIf(D > 30, 9, IIf(D >
25, 10,
11))

[Reports]![Avery 8160 Labels]![Text4].FontSize = IIf(D > 30, 9, IIf(D >
25, 10,
11))

End Sub
 
D

Duane Hookom

Access/VBA will allow you to dim almost everything as variants. Good
programming practices suggests you should dim to the appropriate data type.

Rather than:
Dim A, B, C, D As Integer

If you want all of these dim'd as integer, use:
Dim A As Integer
Dim B As Integer
Dim C As Integer
Dim D As Integer

I would actually write this as the following for ease of maintenance:
Dim intLenFullName As Integer
Dim intLenStreet As Integer
Dim intLenCSZ As Integer
Dim intLenAllText As Integer
 

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