Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.ms-access > #9515 > unrolled thread

Report determining the number of lines in a CanGrow TextBox

Started by"Phil" <phil@stantonfamily.co.uk>
First post2014-06-14 12:20 +0100
Last post2014-06-18 10:34 +0200
Articles 10 — 4 participants

Back to article view | Back to comp.databases.ms-access


Contents

  Report determining the number of lines in a CanGrow TextBox "Phil" <phil@stantonfamily.co.uk> - 2014-06-14 12:20 +0100
    Re: Report determining the number of lines in a CanGrow TextBox DFS <nospam@dfs.com> - 2014-06-14 09:11 -0400
    Re: Report determining the number of lines in a CanGrow TextBox Ulrich Möller <knobbi38@usenet.arcornews.de> - 2014-06-14 17:25 +0200
      Re: Report determining the number of lines in a CanGrow TextBox "Phil" <phil@stantonfamily.co.uk> - 2014-06-16 17:08 +0100
        Re: Report determining the number of lines in a CanGrow TextBox Patrick Finucane <patrickfinucanetx@gmail.com> - 2014-06-16 09:31 -0700
        Re: Report determining the number of lines in a CanGrow TextBox Ulrich Möller <knobbi38@usenet.arcornews.de> - 2014-06-16 21:40 +0200
          Re: Report determining the number of lines in a CanGrow TextBox "Phil" <phil@stantonfamily.co.uk> - 2014-06-16 23:46 +0100
            Re: Report determining the number of lines in a CanGrow TextBox Ulrich Möller <knobbi38@usenet.arcornews.de> - 2014-06-17 14:29 +0200
              Re: Report determining the number of lines in a CanGrow TextBox "Phil" <phil@stantonfamily.co.uk> - 2014-06-17 16:56 +0100
                Re: Report determining the number of lines in a CanGrow TextBox Ulrich Möller <knobbi38@usenet.arcornews.de> - 2014-06-18 10:34 +0200

#9515 — Report determining the number of lines in a CanGrow TextBox

From"Phil" <phil@stantonfamily.co.uk>
Date2014-06-14 12:20 +0100
SubjectReport determining the number of lines in a CanGrow TextBox
Message-ID<lnhb5m$5hi$1@speranza.aioe.org>
I have a report which among other things prints a person’s email address.  
The field width is limited, so in about 30% of the addresses,the Email
address needs 2 lines. The TextBox is set to CanGrow and CanShrink and will
hold about 22 characters. On the OnFormat of the detail, I have a routine
that checks the length of the Email address against the width of the TextBox,
and if it is too long, I add a linefeed before the “@” in the email address.
Works fine except where a person’s email address is of the form
XXXXX@YYYYYYYY.ZZZZZZZZZZ.Co.UK. Then I only get the XXXXX on the first line
and the address spills onto the third line. So I need advice on how to
determine if it will spill over to the third line, then I can insert the
linefeed before the first “.”

Thanks

Phil

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

[toc] | [next] | [standalone]


#9516

FromDFS <nospam@dfs.com>
Date2014-06-14 09:11 -0400
Message-ID<lnhhmt$ud7$2@dont-email.me>
In reply to#9515
On 6/14/2014 7:20 AM, Phil wrote:
> I have a report which among other things prints a person’s email address.
> The field width is limited, so in about 30% of the addresses,the Email
> address needs 2 lines. The TextBox is set to CanGrow and CanShrink and will
> hold about 22 characters. On the OnFormat of the detail, I have a routine
> that checks the length of the Email address against the width of the TextBox,
> and if it is too long, I add a linefeed before the “@” in the email address.
> Works fine except where a person’s email address is of the form
> XXXXX@YYYYYYYY.ZZZZZZZZZZ.Co.UK. Then I only get the XXXXX on the first line
> and the address spills onto the third line. So I need advice on how to
> determine if it will spill over to the third line, then I can insert the
> linefeed before the first “.”


Sounds like you'll need to count the total characters, and find the 
position of the @ and one or two periods.  Then if necessary, insert 
your line feeds at those points.


  'VARS
  Dim email As String
  Dim amp As Byte, p1 As Byte, p2 As Byte

  'TEST CASES
  email = "XXXXX@YYYYYYYY.ZZZZZZZZZZ.Co.UK"
  email = "name@someisp.com"
  email = "phil.name@philsisp.co.uk"

  'FIND POSITIONS OF @ AND FIRST 2 PERIODS
  amp = InStr(email, "@")
  p1 = InStr(email, ".")
  p2 = InStr(p1 + 1, email, ".")

  p2 will be 0 if there's only one period in the email address.

I'll leave the insert line-feed code as an exercise for you.



Or easiest of all: make your report field wide enough so when it grows 
to 2 lines it's able to fully show 100% of the emails in your list.

[toc] | [prev] | [next] | [standalone]


#9517

FromUlrich Möller <knobbi38@usenet.arcornews.de>
Date2014-06-14 17:25 +0200
Message-ID<lnhph0$jco$1@dont-email.me>
In reply to#9515
Am 14.06.2014 13:20, schrieb Phil:
> I have a report which among other things prints a person’s email address.
> The field width is limited, so in about 30% of the addresses,the Email
> address needs 2 lines. The TextBox is set to CanGrow and CanShrink and will
> hold about 22 characters. On the OnFormat of the detail, I have a routine
> that checks the length of the Email address against the width of the TextBox,
> and if it is too long, I add a linefeed before the “@” in the email address.
> Works fine except where a person’s email address is of the form
> XXXXX@YYYYYYYY.ZZZZZZZZZZ.Co.UK. Then I only get the XXXXX on the first line
> and the address spills onto the third line. So I need advice on how to
> determine if it will spill over to the third line, then I can insert the
> linefeed before the first “.”
>
> Thanks
>
> Phil
>
> ---
> This email is free from viruses and malware because avast! Antivirus protection is active.
> http://www.avast.com
>
Hi Phil,

in a report you can use the reports textheight and textwidth properties. 
In combination with the fontsize property you will be able to do the 
calculations

E.x.
me.fontsize = textbox.fontsize
count_of_rows = me.textwidth(strAddress) / textbox.width

Ulrich

[toc] | [prev] | [next] | [standalone]


#9524

From"Phil" <phil@stantonfamily.co.uk>
Date2014-06-16 17:08 +0100
Message-ID<lnn4q2$l18$1@speranza.aioe.org>
In reply to#9517
On 14/06/2014 16:25:23, Ulrich Möller wrote:
> Am 14.06.2014 13:20, schrieb Phil:
>> I have a report which among other things prints a person’s email address.
>> The field width is limited, so in about 30% of the addresses,the Email
>> address needs 2 lines. The TextBox is set to CanGrow and CanShrink and will
>> hold about 22 characters. On the OnFormat of the detail, I have a routine
>> that checks the length of the Email address against the width of the TextBox,
>> and if it is too long, I add a linefeed before the “@” in the email address.
>> Works fine except where a person’s email address is of the form
>> XXXXX@YYYYYYYY.ZZZZZZZZZZ.Co.UK. Then I only get the XXXXX on the first line
>> and the address spills onto the third line. So I need advice on how to
>> determine if it will spill over to the third line, then I can insert the
>> linefeed before the first “.”
>>
>> Thanks
>>
>> Phil
>>
>> ---
>> This email is free from viruses and malware because avast! Antivirus protection is active.
>> http://www.avast.com>
> Hi Phil,
> 
> in a report you can use the reports textheight and textwidth properties.
> In combination with the fontsize property you will be able to do the
> calculations
> 
> E.x.
> me.fontsize  textbox.fontsize
> count_of_rows  me.textwidth(strAddress) / textbox.width
> 
> Ulrich
> 
> 

Good thought Ulrich, but unless I am using it incorrectly, I get silly
results. For test purposes, I have a field called NameLength with a black
border so that the size of the field can be seen. Bound to MemName (Surname &
First name)

Bit of Code
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

    With NameLength
        .Width = ftextwidth(NameLength) + 70
        '.Width = Me.TextWidth(NameLength) + 800
    End With
    
End Sub

I won’t bore you with the details of flextwidth (it’s a bit of code written
by Stephen Lebans) but returns pretty accurate results, but I usually have to
add the “Fiddle Factor” of 70.

Using .Width = Me.TextWidth(NameLength) + 800 (800 is the fiddle factor) is
far too big for some names and barely big enough for other names.

So, am I using TextWidth correctly? If so with the “wrong results” I think
your suggestion will work, but using ftextwidth instead of TextWidth.

I shall play….

Thanks,

Phil

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

[toc] | [prev] | [next] | [standalone]


#9525

FromPatrick Finucane <patrickfinucanetx@gmail.com>
Date2014-06-16 09:31 -0700
Message-ID<46962aba-5f6e-475a-97de-f71b08af6d6a@googlegroups.com>
In reply to#9524
On Monday, June 16, 2014 11:08:36 AM UTC-5, Phil wrote:
> On 14/06/2014 16:25:23, Ulrich Möller wrote: > Am 14.06.2014 13:20, schrieb Phil: >> I have a report which among other things prints a person’s email address. >> The field width is limited, so in about 30% of the addresses,the Email >> address needs 2 lines. The TextBox is set to CanGrow and CanShrink and will >> hold about 22 characters. On the OnFormat of the detail, I have a routine >> that checks the length of the Email address against the width of the TextBox, >> and if it is too long, I add a linefeed before the “@” in the email address. >> Works fine except where a person’s email address is of the form >> XXXXX@YYYYYYYY.ZZZZZZZZZZ.Co.UK. Then I only get the XXXXX on the first line >> and the address spills onto the third line. So I need advice on how to >> determine if it will spill over to the third line, then I can insert the >> linefeed before the first “.” >> >> Thanks >> >> Phil >> >> --- >> This email is free from viruses and malware because avast! Antivirus protection is active. >> http://www.avast.com> > Hi Phil, > > in a report you can use the reports textheight and textwidth properties. > In combination with the fontsize property you will be able to do the > calculations > > E.x. > me.fontsize textbox.fontsize > count_of_rows me.textwidth(strAddress) / textbox.width > > Ulrich > > Good thought Ulrich, but unless I am using it incorrectly, I get silly results. For test purposes, I have a field called NameLength with a black border so that the size of the field can be seen. Bound to MemName (Surname & First name) Bit of Code Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer) With NameLength .Width = ftextwidth(NameLength) + 70 '.Width = Me.TextWidth(NameLength) + 800 End With End Sub I won�t bore you with the details of flextwidth (it�s a bit of code written by Stephen Lebans) but returns pretty accurate results, but I usually have to add the �Fiddle Factor� of 70. Using .Width = Me.TextWidth(NameLength) + 800 (800 is the fiddle factor) is far too big for some names and barely big enough for other names. So, am I using TextWidth correctly? If so with the �wrong results� I think your suggestion will work, but using ftextwidth instead of TextWidth. I shall play�. Thanks, Phil --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com

Phil, why wouldn't TextWidth work?  Why use Mr. Lebans fudge factor code?  From help, it states..."You can use the TextWidth method to determine the amount of horizontal space a text string will require in the current font when the report is formatted and printed. For example, a text string formatted in 9-point Arial will require a different amount of space than one formatted in 12-point Courier. To determine the current font and font size for text in a report, check the settings for the report's FontName and FontSize properties."

Ulrich's solution seems on the mark.

[toc] | [prev] | [next] | [standalone]


#9527

FromUlrich Möller <knobbi38@usenet.arcornews.de>
Date2014-06-16 21:40 +0200
Message-ID<lnnh6p$sv7$1@dont-email.me>
In reply to#9524
Am 16.06.2014 18:08, schrieb Phil:
> On 14/06/2014 16:25:23, Ulrich Möller wrote:
>> Am 14.06.2014 13:20, schrieb Phil:
>>> I have a report which among other things prints a person’s email address.
>>> The field width is limited, so in about 30% of the addresses,the Email
>>> address needs 2 lines. The TextBox is set to CanGrow and CanShrink and will
>>> hold about 22 characters. On the OnFormat of the detail, I have a routine
>>> that checks the length of the Email address against the width of the TextBox,
>>> and if it is too long, I add a linefeed before the “@” in the email address.
>>> Works fine except where a person’s email address is of the form
>>> XXXXX@YYYYYYYY.ZZZZZZZZZZ.Co.UK. Then I only get the XXXXX on the first line
>>> and the address spills onto the third line. So I need advice on how to
>>> determine if it will spill over to the third line, then I can insert the
>>> linefeed before the first “.”
>>>
>>> Thanks
>>>
>>> Phil
>>>
>>> ---
>>> This email is free from viruses and malware because avast! Antivirus protection is active.
>>> http://www.avast.com>
>> Hi Phil,
>>
>> in a report you can use the reports textheight and textwidth properties.
>> In combination with the fontsize property you will be able to do the
>> calculations
>>
>> E.x.
>> me.fontsize  textbox.fontsize
>> count_of_rows  me.textwidth(strAddress) / textbox.width
>>
>> Ulrich
>>
>>
> Good thought Ulrich, but unless I am using it incorrectly, I get silly
> results. For test purposes, I have a field called NameLength with a black
> border so that the size of the field can be seen. Bound to MemName (Surname &
> First name)
>
> Bit of Code
> Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
>
>      With NameLength
>          .Width = ftextwidth(NameLength) + 70
>          '.Width = Me.TextWidth(NameLength) + 800
>      End With
>      
> End Sub
>
> I won�t bore you with the details of flextwidth (it�s a bit of code written
> by Stephen Lebans) but returns pretty accurate results, but I usually have to
> add the �Fiddle Factor� of 70.
>
> Using .Width = Me.TextWidth(NameLength) + 800 (800 is the fiddle factor) is
> far too big for some names and barely big enough for other names.
>
> So, am I using TextWidth correctly? If so with the �wrong results� I think
> your suggestion will work, but using ftextwidth instead of TextWidth.
>
> I shall play�.
>
> Thanks,
>
> Phil
>
> ---
> This email is free from viruses and malware because avast! Antivirus protection is active.
> http://www.avast.com
>
Hi Phil,

in your snippet you are going to resize the width of the textbox 
depending of its value and normally it should work with textwidth in 
this case. Ensure that the current font of the report and the textbox 
are the same and pay attention to the scalemode of the report. Bear in 
mind how access deals with borderwidth and paddings of a textbox and 
play a little bit around with the constant "fiddle factor" with the 
given scale unit (twips, pixels, inch ...)

A little code snippet of mine which i use in a report to reduce the 
fontsize of the textbox so its contents will be fully displayed. The 
minimal fontsize in this example is restricted to 6 pt. Not the same 
problem but perhaps it will give you a hint.

Private Function CalcFontSize(ByVal Textbox As Access.Textbox) As Integer
' Calculates the maxmimal fontsize
Dim strOldFontName As String
Dim intOldFontSize As Integer
Dim intRows As Integer
Dim sngWidth As Single

CalcFontSize = Textbox.FontSize

If IsNull(Textbox.Value) Then Exit Function

If Len(Textbox.Value) > 0 Then
strOldFontName = Me.FontName
intOldFontSize = Me.FontSize

' save current values
Me.FontName = Textbox.FontName
Me.FontSize = Textbox.FontSize

Do While Me.FontSize > 6
intRows = Textbox.Height \ Me.TextHeight(Textbox.Value)

If Me.TextWidth(Textbox.Value) \ intRows > Textbox.Width Then
Me.FontSize = Me.FontSize - 1
Else
Exit Do
End If
Loop

CalcFontSize = Me.FontSize

' restore original values
Me.FontName = strOldFontName
Me.FontSize = intOldFontSize
End If

Ulrich

[toc] | [prev] | [next] | [standalone]


#9528

From"Phil" <phil@stantonfamily.co.uk>
Date2014-06-16 23:46 +0100
Message-ID<lnns3c$nj4$1@speranza.aioe.org>
In reply to#9527
On 16/06/2014 20:40:07, Ulrich Möller wrote:
> Am 16.06.2014 18:08, schrieb Phil:
>> On 14/06/2014 16:25:23, Ulrich Möller wrote:
>>> Am 14.06.2014 13:20, schrieb Phil:
>>>> I have a report which among other things prints a person’s email address.
>>>> The field width is limited, so in about 30% of the addresses,the Email
>>>> address needs 2 lines. The TextBox is set to CanGrow and CanShrink and will
>>>> hold about 22 characters. On the OnFormat of the detail, I have a routine
>>>> that checks the length of the Email address against the width of the TextBox,
>>>> and if it is too long, I add a linefeed before the “@” in the email address.
>>>> Works fine except where a person’s email address is of the form
>>>> XXXXX@YYYYYYYY.ZZZZZZZZZZ.Co.UK. Then I only get the XXXXX on the first line
>>>> and the address spills onto the third line. So I need advice on how to
>>>> determine if it will spill over to the third line, then I can insert the
>>>> linefeed before the first “.”
>>>>
>>>> Thanks
>>>>
>>>> Phil
>>>>
>>>> ---
>>>> This email is free from viruses and malware because avast! Antivirus protection is active.
>>>> http://www.avast.com>>> Hi Phil,
>>>
>>> in a report you can use the reports textheight and textwidth properties.
>>> In combination with the fontsize property you will be able to do the
>>> calculations
>>>
>>> E.x.
>>> me.fontsize  textbox.fontsize
>>> count_of_rows  me.textwidth(strAddress) / textbox.width
>>>
>>> Ulrich
>>>
>>>
>> Good thought Ulrich, but unless I am using it incorrectly, I get silly
>> results. For test purposes, I have a field called NameLength with a black
>> border so that the size of the field can be seen. Bound to MemName (Surname &
>> First name)
>>
>> Bit of Code
>> Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
>>
>>      With NameLength
>>          .Width  ftextwidth(NameLength) + 70
>>          '.Width  Me.TextWidth(NameLength) + 800
>>      End With
>>
>> End Sub
>>
>> I won�t bore you with the details of flextwidth (it�s a bit of code written
>> by Stephen Lebans) but returns pretty accurate results, but I usually have to
>> add the �Fiddle Factor� of 70.
>>
>> Using .Width  Me.TextWidth(NameLength) + 800 (800 is the fiddle factor) is
>> far too big for some names and barely big enough for other names.
>>
>> So, am I using TextWidth correctly? If so with the �wrong results� I think
>> your suggestion will work, but using ftextwidth instead of TextWidth.
>>
>> I shall play�.
>>
>> Thanks,
>>
>> Phil
>>
>> ---
>> This email is free from viruses and malware because avast! Antivirus protection is active.
>> http://www.avast.com>
> Hi Phil,
> 
> in your snippet you are going to resize the width of the textbox
> depending of its value and normally it should work with textwidth in
> this case. Ensure that the current font of the report and the textbox
> are the same and pay attention to the scalemode of the report. Bear in
> mind how access deals with borderwidth and paddings of a textbox and
> play a little bit around with the constant "fiddle factor" with the
> given scale unit (twips, pixels, inch ...)
> 
> A little code snippet of mine which i use in a report to reduce the
> fontsize of the textbox so its contents will be fully displayed. The
> minimal fontsize in this example is restricted to 6 pt. Not the same
> problem but perhaps it will give you a hint.
> 
> Private Function CalcFontSize(ByVal Textbox As Access.Textbox) As Integer
> ' Calculates the maxmimal fontsize
> Dim strOldFontName As String
> Dim intOldFontSize As Integer
> Dim intRows As Integer
> Dim sngWidth As Single
> 
> CalcFontSize  Textbox.FontSize
> 
> If IsNull(Textbox.Value) Then Exit Function
> 
> If Len(Textbox.Value) > 0 Then
> strOldFontName  Me.FontName
> intOldFontSize  Me.FontSize
> 
> ' save current values
> Me.FontName  Textbox.FontName
> Me.FontSize  Textbox.FontSize
> 
> Do While Me.FontSize > 6
> intRows  Textbox.Height \ Me.TextHeight(Textbox.Value)
> 
> If Me.TextWidth(Textbox.Value) \ intRows > Textbox.Width Then
> Me.FontSize  Me.FontSize - 1
> Else
> Exit Do
> End If
> Loop
> 
> CalcFontSize  Me.FontSize
> 
> ' restore original values
> Me.FontName  strOldFontName
> Me.FontSize  intOldFontSize
> End If
> 
> Ulrich
> 

Thanks Ulrich & Patrick

If you look at https://www.flickr.com/photos/philofwaltonspics/ top left hand
image, the second column’s width is using FTextWidth and the third column
using TextWidth. The FTextWidth column seems pretty well perfect, whilst the
TextWidth column is sometimes correct, sometimes too long and sometimes too
short.

Have slightly changed the code to:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

    Me.ScaleMode = 1
        
    With NameLength
Debug.Print bug.Print ftextwidth(NameLength); " "; .LeftMargin; " ";
LeftPadding         .Width = ftextwidth(NameLength) + 70
    End With
    
    With NameLength1
        .Width = Me.TextWidth(NameLength) + 800
    End With
   
End Sub

The left and right padding are 30 and the left & right margin are 0 according
to the Debug line. The FTextWidth varies from about 1400 to 2700
I think Ulrich’s code doesn’t take into the account the size of the letter in
that an “m” or “w” are about twice as wide as an “n” and about 5 times as
wide as an “I” or “j”. I appreciate this is more to calculate what size font
to use rather than the original problem of the most elegant place to put a
line feed so that the email address can be read easily.

Phil

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

[toc] | [prev] | [next] | [standalone]


#9529

FromUlrich Möller <knobbi38@usenet.arcornews.de>
Date2014-06-17 14:29 +0200
Message-ID<lnpcbm$5e5$1@dont-email.me>
In reply to#9528
Am 17.06.2014 00:46, schrieb Phil:
> On 16/06/2014 20:40:07, Ulrich Möller wrote:
>> Am 16.06.2014 18:08, schrieb Phil:
>>> On 14/06/2014 16:25:23, Ulrich Möller wrote:
>>>> Am 14.06.2014 13:20, schrieb Phil:
>>>>> I have a report which among other things prints a person’s email address.
>>>>> The field width is limited, so in about 30% of the addresses,the Email
>>>>> address needs 2 lines. The TextBox is set to CanGrow and CanShrink and will
>>>>> hold about 22 characters. On the OnFormat of the detail, I have a routine
>>>>> that checks the length of the Email address against the width of the TextBox,
>>>>> and if it is too long, I add a linefeed before the “@” in the email address.
>>>>> Works fine except where a person’s email address is of the form
>>>>> XXXXX@YYYYYYYY.ZZZZZZZZZZ.Co.UK. Then I only get the XXXXX on the first line
>>>>> and the address spills onto the third line. So I need advice on how to
>>>>> determine if it will spill over to the third line, then I can insert the
>>>>> linefeed before the first “.”
>>>>>
>>>>> Thanks
>>>>>
>>>>> Phil
>>>>>
>>>>> ---
>>>>> This email is free from viruses and malware because avast! Antivirus protection is active.
>>>>> http://www.avast.com>>> Hi Phil,
>>>> in a report you can use the reports textheight and textwidth properties.
>>>> In combination with the fontsize property you will be able to do the
>>>> calculations
>>>>
>>>> E.x.
>>>> me.fontsize  textbox.fontsize
>>>> count_of_rows  me.textwidth(strAddress) / textbox.width
>>>>
>>>> Ulrich
>>>>
>>>>
>>> Good thought Ulrich, but unless I am using it incorrectly, I get silly
>>> results. For test purposes, I have a field called NameLength with a black
>>> border so that the size of the field can be seen. Bound to MemName (Surname &
>>> First name)
>>>
>>> Bit of Code
>>> Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
>>>
>>>       With NameLength
>>>           .Width  ftextwidth(NameLength) + 70
>>>           '.Width  Me.TextWidth(NameLength) + 800
>>>       End With
>>>
>>> End Sub
>>>
>>> I won�t bore you with the details of flextwidth (it�s a bit of code written
>>> by Stephen Lebans) but returns pretty accurate results, but I usually have to
>>> add the �Fiddle Factor� of 70.
>>>
>>> Using .Width  Me.TextWidth(NameLength) + 800 (800 is the fiddle factor) is
>>> far too big for some names and barely big enough for other names.
>>>
>>> So, am I using TextWidth correctly? If so with the �wrong results� I think
>>> your suggestion will work, but using ftextwidth instead of TextWidth.
>>>
>>> I shall play�.
>>>
>>> Thanks,
>>>
>>> Phil
>>>
>>> ---
>>> This email is free from viruses and malware because avast! Antivirus protection is active.
>>> http://www.avast.com>
>> Hi Phil,
>>
>> in your snippet you are going to resize the width of the textbox
>> depending of its value and normally it should work with textwidth in
>> this case. Ensure that the current font of the report and the textbox
>> are the same and pay attention to the scalemode of the report. Bear in
>> mind how access deals with borderwidth and paddings of a textbox and
>> play a little bit around with the constant "fiddle factor" with the
>> given scale unit (twips, pixels, inch ...)
>>
>> A little code snippet of mine which i use in a report to reduce the
>> fontsize of the textbox so its contents will be fully displayed. The
>> minimal fontsize in this example is restricted to 6 pt. Not the same
>> problem but perhaps it will give you a hint.
>>
>> Private Function CalcFontSize(ByVal Textbox As Access.Textbox) As Integer
>> ' Calculates the maxmimal fontsize
>> Dim strOldFontName As String
>> Dim intOldFontSize As Integer
>> Dim intRows As Integer
>> Dim sngWidth As Single
>>
>> CalcFontSize  Textbox.FontSize
>>
>> If IsNull(Textbox.Value) Then Exit Function
>>
>> If Len(Textbox.Value) > 0 Then
>> strOldFontName  Me.FontName
>> intOldFontSize  Me.FontSize
>>
>> ' save current values
>> Me.FontName  Textbox.FontName
>> Me.FontSize  Textbox.FontSize
>>
>> Do While Me.FontSize > 6
>> intRows  Textbox.Height \ Me.TextHeight(Textbox.Value)
>>
>> If Me.TextWidth(Textbox.Value) \ intRows > Textbox.Width Then
>> Me.FontSize  Me.FontSize - 1
>> Else
>> Exit Do
>> End If
>> Loop
>>
>> CalcFontSize  Me.FontSize
>>
>> ' restore original values
>> Me.FontName  strOldFontName
>> Me.FontSize  intOldFontSize
>> End If
>>
>> Ulrich
>>
> Thanks Ulrich & Patrick
>
> If you look at https://www.flickr.com/photos/philofwaltonspics/ top left hand
> image, the second column�s width is using FTextWidth and the third column
> using TextWidth. The FTextWidth column seems pretty well perfect, whilst the
> TextWidth column is sometimes correct, sometimes too long and sometimes too
> short.
>
> Have slightly changed the code to:
>
> Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
>
>      Me.ScaleMode = 1
>          
>      With NameLength
> Debug.Print bug.Print ftextwidth(NameLength); " "; .LeftMargin; " ";
> LeftPadding         .Width = ftextwidth(NameLength) + 70
>      End With
>      
>      With NameLength1
>          .Width = Me.TextWidth(NameLength) + 800
>      End With
>     
> End Sub
>
> The left and right padding are 30 and the left & right margin are 0 according
> to the Debug line. The FTextWidth varies from about 1400 to 2700
> I think Ulrich�s code doesn�t take into the account the size of the letter in
> that an �m� or �w� are about twice as wide as an �n� and about 5 times as
> wide as an �I� or �j�. I appreciate this is more to calculate what size font
> to use rather than the original problem of the most elegant place to put a
> line feed so that the email address can be read easily.
>
> Phil
>
> ---
> This email is free from viruses and malware because avast! Antivirus protection is active.
> http://www.avast.com
>
Hi Phil,

i just have tested it with the customers table from the northwind db and 
an automatically created report with only the companyname field.

The report.textwidth method works as expected with the exception that 
there is a need to add a constant factor to the returned textwidth. 
Don't know why.

Here is the testcode i used:

Private Sub Detailbereich_Format(Cancel As Integer, FormatCount As Integer)

' Reset to twips
Me.ScaleMode = 1
Me.Scale

Me.FontName = txtCompanyName.FontName
Me.FontSize = txtCompanyName.FontSize

' Reset to original textbox width
txtCompanyName.Width = 800
txtCompanyName.Width = Me.TextWidth(txtCompanyName.Value) + 70
Debug.Print txtCompanyName.Width, Me.TextWidth(txtCompanyName.Value)
End Sub

But if ftextwidth() worked for you... why not?

Ulrich

[toc] | [prev] | [next] | [standalone]


#9530

From"Phil" <phil@stantonfamily.co.uk>
Date2014-06-17 16:56 +0100
Message-ID<lnpoep$psm$1@speranza.aioe.org>
In reply to#9529
> 
> Private Sub Detailbereich_Format(Cancel As Integer, FormatCount As
> Integer)
> 
> ' Reset to twips
> Me.ScaleMode  1
> Me.Scale
> 
> Me.FontName  txtCompanyName.FontName
> Me.FontSize  txtCompanyName.FontSize
> 
> ' Reset to original textbox width
> txtCompanyName.Width  800
> txtCompanyName.Width  Me.TextWidth(txtCompanyName.Value) + 70
> Debug.Print txtCompanyName.Width, Me.TextWidth(txtCompanyName.Value)
> End Sub
> 
> But if ftextwidth() worked for you... why not?
> 
> Ulrich
> 
Using your code (Had to modify it as it wouldn't compile, (Needed “=” signs
and changing the fiddle factor to 150.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

    Me.ScaleMode = 1
    Me.Scale
    
    Me.FontName = TxtCompanyName.FontName
    Me.FontSize = TxtCompanyName.FontSize
    
    ' Reset to original textbox width
    'TxtCompanyName.Width = 800
    TxtCompanyName.Width = Me.TextWidth(TxtCompanyName.Value) + 150
Debug.Print rint TxtCompanyName.Width; " ";
Me.TextWidth(TxtCompanyName.Value); _ " "; TxtCompanyName.FontName; " ";
TxtCompanyName.FontSize; _ " "; TxtCompanyName.FontBold; " ";
TxtCompanyName.FontItalic End Sub

I Also changed “Company A” to “Co A” and whatever you put in for me to
“Phil’s very big Company” Record 31 Company is iiiiiiiiii and record 32
company is mmmmmmmmmm to give a variety of lengths. In addition I filtered on
record ID 1, 5 & 30 31 & 32 so that only 5 records came up on the reports and
similar Debugs.

All worked except the Bold Font and the debug window reveals why

TextWidth: 610   FTextWidth: 610   Arial   14    0   False
TextWidth: 1462   FTextWidth: 1462   Arial   14    0   False
TextWidth: 2940   FTextWidth: 2940   Arial   14    0   False
TextWidth: 744   FTextWidth: 749   Arial   14    0   False
TextWidth: 2330   FTextWidth: 2328   Arial   14    0   False

TextWidth: 610   FTextWidth: 636   Arial   14    1   False
TextWidth: 1462   FTextWidth: 1531   Arial   14    1   False
TextWidth: 2940   FTextWidth: 3161   Arial   14    1   False
TextWidth: 744   FTextWidth: 950   Arial   14    1   False
TextWidth: 2330   FTextWidth: 2496   Arial   14    1   False

TextWidth: 610   FTextWidth: 614   Arial   14    0   True
TextWidth: 1462   FTextWidth: 1466   Arial   14    0   True
TextWidth: 2940   FTextWidth: 2954   Arial   14    0   True
TextWidth: 744   FTextWidth: 749   Arial   14    0   True
TextWidth: 2330   FTextWidth: 2328   Arial   14    0   True


The TextWidth seems to take account of the font, it’s size and the big
letters (“m” & “w”) and the small letters (“I” & “J”), but no account of the
bold or italic settings whilst the FTextWidth appears to take them into
account.

Thought you might be interested.

Phil



---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

[toc] | [prev] | [next] | [standalone]


#9531

FromUlrich Möller <knobbi38@usenet.arcornews.de>
Date2014-06-18 10:34 +0200
Message-ID<lnriur$ptg$1@dont-email.me>
In reply to#9530
Am 17.06.2014 17:56, schrieb Phil:
>> Private Sub Detailbereich_Format(Cancel As Integer, FormatCount As
>> Integer)
>>
>> ' Reset to twips
>> Me.ScaleMode  1
>> Me.Scale
>>
>> Me.FontName  txtCompanyName.FontName
>> Me.FontSize  txtCompanyName.FontSize
>>
>> ' Reset to original textbox width
>> txtCompanyName.Width  800
>> txtCompanyName.Width  Me.TextWidth(txtCompanyName.Value) + 70
>> Debug.Print txtCompanyName.Width, Me.TextWidth(txtCompanyName.Value)
>> End Sub
>>
>> But if ftextwidth() worked for you... why not?
>>
>> Ulrich
>>
> Using your code (Had to modify it as it wouldn't compile, (Needed “=” signs
> and changing the fiddle factor to 150.
>
> Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
>
>      Me.ScaleMode = 1
>      Me.Scale
>      
>      Me.FontName = TxtCompanyName.FontName
>      Me.FontSize = TxtCompanyName.FontSize
>      
>      ' Reset to original textbox width
>      'TxtCompanyName.Width = 800
>      TxtCompanyName.Width = Me.TextWidth(TxtCompanyName.Value) + 150
> Debug.Print rint TxtCompanyName.Width; " ";
> Me.TextWidth(TxtCompanyName.Value); _ " "; TxtCompanyName.FontName; " ";
> TxtCompanyName.FontSize; _ " "; TxtCompanyName.FontBold; " ";
> TxtCompanyName.FontItalic End Sub
>
> I Also changed “Company A” to “Co A” and whatever you put in for me to
> “Phil’s very big Company” Record 31 Company is iiiiiiiiii and record 32
> company is mmmmmmmmmm to give a variety of lengths. In addition I filtered on
> record ID 1, 5 & 30 31 & 32 so that only 5 records came up on the reports and
> similar Debugs.
>
> All worked except the Bold Font and the debug window reveals why
>
> TextWidth: 610   FTextWidth: 610   Arial   14    0   False
> TextWidth: 1462   FTextWidth: 1462   Arial   14    0   False
> TextWidth: 2940   FTextWidth: 2940   Arial   14    0   False
> TextWidth: 744   FTextWidth: 749   Arial   14    0   False
> TextWidth: 2330   FTextWidth: 2328   Arial   14    0   False
>
> TextWidth: 610   FTextWidth: 636   Arial   14    1   False
> TextWidth: 1462   FTextWidth: 1531   Arial   14    1   False
> TextWidth: 2940   FTextWidth: 3161   Arial   14    1   False
> TextWidth: 744   FTextWidth: 950   Arial   14    1   False
> TextWidth: 2330   FTextWidth: 2496   Arial   14    1   False
>
> TextWidth: 610   FTextWidth: 614   Arial   14    0   True
> TextWidth: 1462   FTextWidth: 1466   Arial   14    0   True
> TextWidth: 2940   FTextWidth: 2954   Arial   14    0   True
> TextWidth: 744   FTextWidth: 749   Arial   14    0   True
> TextWidth: 2330   FTextWidth: 2328   Arial   14    0   True
>
>
> The TextWidth seems to take account of the font, it’s size and the big
> letters (“m” & “w”) and the small letters (“I” & “J”), but no account of the
> bold or italic settings whilst the FTextWidth appears to take them into
> account.
>
> Thought you might be interested.
>
> Phil
>
>
>
> ---
> This email is free from viruses and malware because avast! Antivirus protection is active.
> http://www.avast.com
>
Thanks Phil for your notice. I didn't be aware of it. It seems that the 
function textwidth has been a little bit carelessly handled by MS 
Anyway, in my reports it does not matter.

I wonder, where the equals signs have gone.

Ulrich

[toc] | [prev] | [standalone]


Back to top | Article view | comp.databases.ms-access


csiph-web