Solved Number doesnt fit (1 Viewer)

Hello1

Registered User.
Local time
Today, 20:13
Joined
May 17, 2015
Messages
271
I run the same report on 2 different machines (one is windows 10 with access 2007 12.0.4518, and the other one is Windows 7 with Access 2007 12.0.6735).
Regional settings are the same.
There is a number field which has the standard format #,###.##.
On the Windows 10 machine the 4 digit number (3 digit numbers I can see fine on both) is shown fine (like 0.000,00) but on the Windows 7 machine all I see is ##########.
I wonder why is that? Because the versions of access arent exactly the same?
Is there a way to make the column increase its width automatically once it sees the number cant fit?

Thanks!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:13
Joined
Oct 29, 2018
Messages
21,469
Hi. I think it means one computer doesn't have the same font installed as the other.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:13
Joined
May 7, 2009
Messages
19,237
will work on Print Preview (not Report View):
Code:
' fit text to textbox in report
' can only see the effect on Print Preview
'
' https://www.tek-tips.com/viewthread.cfm?qid=854917
'
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
Dim ctl As control, strText As Variant, strName As String
' This routine uses the TextWidth methods to determine the maximum size
' of font possible to ensure a text string is printed in full in the
' report's current font without loosing any characters.
    
    Me.ScaleMode = 1 ' set all measurments to twips
    
    For Each ctl In Me.Detail.Controls
  
        If ctl.ControlType = acTextBox Then 'And ctl.NAME Like "v*" Then
        
        strName = ctl.NAME
        
            If Nz(ctl.tag, "") = "" Then
                ctl.tag = ctl.fontsize
            End If
            
                
        ' set the control's fontsize to a suitable large size to begin with
            ctl.fontsize = ctl.tag

        ' make sure the report font size is equal to the control's fontsize.
            Me.fontsize = ctl.fontsize
        
        ' grab the text from the control
            strText = ctl.value & ""
        
        ' evaluate the Loop until the text fits the Width of the box less 24%. Do this
        ' by reducing the font size incrementally and re-testing the Loop's criteria.
            Do Until TextWidth(strText) < ctl.Width '- (ctl.Width * 0.26)
                ctl.fontsize = ctl.fontsize - 1
                ' reset the report's font size so the TextWidth function will
                ' continue to track the reducing font size correctly.
                Me.fontsize = ctl.fontsize
            Loop
            
        ' now evaluate for the height of the text to make sure it fits vertically
            Do Until TextHeight(strText) < ctl.Height - (ctl.Height * 0.4)  '(ctl.Height * 0.26)
                ctl.fontsize = ctl.fontsize - 1
                ' reset the report's font size so the TextHeight function will
                ' continue to track the reducing font size correctly.
                Me.fontsize = ctl.fontsize
            Loop
        
        End If
        
    Next ctl
    
End Sub
 

Hello1

Registered User.
Local time
Today, 20:13
Joined
May 17, 2015
Messages
271
Hi. I think it means one computer doesn't have the same font installed as the other.
That's true, it probably could be the reason
will work on Print Preview (not Report View):
Code:
' fit text to textbox in report
' can only see the effect on Print Preview
'
' https://www.tek-tips.com/viewthread.cfm?qid=854917
'
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
Dim ctl As control, strText As Variant, strName As String
' This routine uses the TextWidth methods to determine the maximum size
' of font possible to ensure a text string is printed in full in the
' report's current font without loosing any characters.
   
    Me.ScaleMode = 1 ' set all measurments to twips
   
    For Each ctl In Me.Detail.Controls
 
        If ctl.ControlType = acTextBox Then 'And ctl.NAME Like "v*" Then
       
        strName = ctl.NAME
       
            If Nz(ctl.tag, "") = "" Then
                ctl.tag = ctl.fontsize
            End If
           
               
        ' set the control's fontsize to a suitable large size to begin with
            ctl.fontsize = ctl.tag

        ' make sure the report font size is equal to the control's fontsize.
            Me.fontsize = ctl.fontsize
       
        ' grab the text from the control
            strText = ctl.value & ""
       
        ' evaluate the Loop until the text fits the Width of the box less 24%. Do this
        ' by reducing the font size incrementally and re-testing the Loop's criteria.
            Do Until TextWidth(strText) < ctl.Width '- (ctl.Width * 0.26)
                ctl.fontsize = ctl.fontsize - 1
                ' reset the report's font size so the TextWidth function will
                ' continue to track the reducing font size correctly.
                Me.fontsize = ctl.fontsize
            Loop
           
        ' now evaluate for the height of the text to make sure it fits vertically
            Do Until TextHeight(strText) < ctl.Height - (ctl.Height * 0.4)  '(ctl.Height * 0.26)
                ctl.fontsize = ctl.fontsize - 1
                ' reset the report's font size so the TextHeight function will
                ' continue to track the reducing font size correctly.
                Me.fontsize = ctl.fontsize
            Loop
       
        End If
       
    Next ctl
   
End Sub
Thanks I will try it out
 

Hello1

Registered User.
Local time
Today, 20:13
Joined
May 17, 2015
Messages
271
will work on Print Preview (not Report View):
Code:
' fit text to textbox in report
' can only see the effect on Print Preview
'
' https://www.tek-tips.com/viewthread.cfm?qid=854917
'
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
Dim ctl As control, strText As Variant, strName As String
' This routine uses the TextWidth methods to determine the maximum size
' of font possible to ensure a text string is printed in full in the
' report's current font without loosing any characters.
   
    Me.ScaleMode = 1 ' set all measurments to twips
   
    For Each ctl In Me.Detail.Controls
 
        If ctl.ControlType = acTextBox Then 'And ctl.NAME Like "v*" Then
       
        strName = ctl.NAME
       
            If Nz(ctl.tag, "") = "" Then
                ctl.tag = ctl.fontsize
            End If
           
               
        ' set the control's fontsize to a suitable large size to begin with
            ctl.fontsize = ctl.tag

        ' make sure the report font size is equal to the control's fontsize.
            Me.fontsize = ctl.fontsize
       
        ' grab the text from the control
            strText = ctl.value & ""
       
        ' evaluate the Loop until the text fits the Width of the box less 24%. Do this
        ' by reducing the font size incrementally and re-testing the Loop's criteria.
            Do Until TextWidth(strText) < ctl.Width '- (ctl.Width * 0.26)
                ctl.fontsize = ctl.fontsize - 1
                ' reset the report's font size so the TextWidth function will
                ' continue to track the reducing font size correctly.
                Me.fontsize = ctl.fontsize
            Loop
           
        ' now evaluate for the height of the text to make sure it fits vertically
            Do Until TextHeight(strText) < ctl.Height - (ctl.Height * 0.4)  '(ctl.Height * 0.26)
                ctl.fontsize = ctl.fontsize - 1
                ' reset the report's font size so the TextHeight function will
                ' continue to track the reducing font size correctly.
                Me.fontsize = ctl.fontsize
            Loop
       
        End If
       
    Next ctl
   
End Sub

After short testing it seems this is working pretty nice. I just made a small change for my app.
Instead
Code:
' grab the text from the control
      strText = ctl.Value & ""

I have put
Code:
' grab the text from the control
      If ctl.Format = "Standard" Then
         strText = Format(ctl.Value & "", "##.00")
      Else
         strText = ctl.Value & ""
      End If

Reason for this is that all my controls on the report which contain double or decimal numbers have a standard format.
So the original code would see a decimal number of 22.111111111 as having the width of 1046 while in reality I dont display on my report 22.111111111 but a standard format which would be 22.11, so the actual width is 408

Thanks for the help guys!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:13
Joined
Oct 29, 2018
Messages
21,469
After short testing it seems this is working pretty nice. I just made a small change for my app.
Instead
Code:
' grab the text from the control
      strText = ctl.Value & ""

I have put
Code:
' grab the text from the control
      If ctl.Format = "Standard" Then
         strText = Format(ctl.Value & "", "##.00")
      Else
         strText = ctl.Value & ""
      End If

Reason for this is that all my controls on the report which contain double or decimal numbers have a standard format.
So the original code would see a decimal number of 22.111111111 as having the width of 1046 while in reality I dont display on my report 22.111111111 but a standard format which would be 22.11, so the actual width is 408

Thanks for the help guys!
Hi. Thanks for the update. Glad to hear you got it to work. Good luck with your project.
 

Users who are viewing this thread

Top Bottom