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
 
C

Chuck

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

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
 
C

Chuck

Caution from previous reply
Dim A, B, C, D as Integer
will only Dim D as integer and the others will be variants.
What is the implication of A, B, C being Variants? Since each is the result of
a Len statement doesn't that make them act like a Long data type? And isn't
the difference between Long(integer) and Integer(short integer) only a mater of
accuracy, i.e. number of significant places? A string that will fit on one
line in a mailing label can only be but so long, therefore, D will never be a
'large' number.

It's obvious that I don't understand much about Access. I will gladly make A,
B, and C be integers if that is the preferred technique.

Chuck
--
 
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
 
C

Chuck

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

Thanks for the reply. I like your suggestion of Dim intlen...
I'm going to change my database.

Chuck
 
C

Chuck

Thanks for the reply. I like your suggestion of Dim intlen...
I'm going to change my database.

Chuck

Well, I gave it a try. The equations that look for the longest text string
looked awkward. I guess they would run OK, but if they didn't, I didn't want
to have to debug them. I didn't try to run the program. What I did do was to
Dim A, B, and C individually as integers. That worked fine. I think that for
my simple case, A, B, and C as Variants is OK even if not good technique.

Chuck
--
 

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