Character that displays as a blank

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • OldBirdman
    Contributor
    • Mar 2007
    • 675

    Character that displays as a blank

    Access 2003 strips trailing blanks from text in tables. It also strips trailing blanks for control properties on forms.
    I have a tab control where I want to pad shorter captions with blanks so all tabs are equal width. I want to center these captions, so I need to include trailing blanks that are not stripped by Access.
    What character (hex value) will show on forms as a blank, not a null, but will not be removed by Access?
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by OldBirdman
    Access 2003 strips trailing blanks from text in tables. It also strips trailing blanks for control properties on forms.
    I have a tab control where I want to pad shorter captions with blanks so all tabs are equal width. I want to center these captions, so I need to include trailing blanks that are not stripped by Access.
    What character (hex value) will show on forms as a blank, not a null, but will not be removed by Access?
    Now sure if this will work, but try using the Space() Function. The following code will pad any String will Spaces on the Back End to a Constant Length of 32:
    Code:
    Const conWIDTH As Byte = 32
    Dim strCaption As String
    
    strCaption = "Caption 1"
    
    strCaption = strCaption & Space(32 - Len(strCaption))
    P.S. - Chr$(32) or &H20 will also generate a Space Character

    Comment

    • jimatqsi
      Moderator Top Contributor
      • Oct 2006
      • 1288

      #3
      I think you have stated the problem wrong. If you are centering the captions, then adding blanks to the end will only take the caption off of center alignment and it will tilt to the left.

      The problem is to set the .width property of the tabs. You can do that programmaticall y or with the GUI at design time. There is a property on the tab control called TabFixedWidth. It is normally zero, which lets the tabs vary in width to fit the provided text. Change that setting to be long enough for your widest tab label.

      Jim

      Jim

      Comment

      • jimatqsi
        Moderator Top Contributor
        • Oct 2006
        • 1288

        #4
        Another helpful thing to remember is that you can specify fixed length strings.
        dim A as string * 20 makes a fixed 20 character string. You could also try using that to your advantage here, something like this
        Code:
        dim strA10 as string * 10
        strA10 = tab1.caption
        tab1.caption = strA10
        strA10 = tab2.caption
        tab2.caption= strA10
        strA10 = tab3.caption
        tab3.caption= strA10
        Jim

        Comment

        • OldBirdman
          Contributor
          • Mar 2007
          • 675

          #5
          Space() is a variation of String(). Neither works for this. Whether I enter "XXX ", "XXX" & Space(5), "XXX" & String(5, 32), or "XXX" & " ", the results are the same, when entered into a table.
          For assigning to .Caption in design view of a form, the text becomes literal, and my tab contains "XXX & Space(5)"
          Assigning into .Caption at runtime doesn't work either. Access strips the trailing blanks.

          I'm tracking use of a building, 4 floors, 6 rooms/floor.
          I wanted the tab control to be:
          Code:
             1      2      3      4      5      6
            101    102    103    104    105    106
            201    202    203    204    205    206
            301    302    303    304    305    306
               Office           Storage Room
          I thought if I could enter " 2 " for room #2, I could make the tabs show as a matrix, and fill the row space. But " 2 " becomes " 2" for all these suggestions.

          I can live with Fixed Width Tabs. I was just hoping for either fixed widths per each tab, or using blanks to force the width to larger than Access default.

          Note: This site strips blanks, so my example for room #2 with 3 leading and 3 trailing blanks is stripped to one each.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32633

            #6
            I expect it depends on your CodePage OB, but with some preliminary tests I found 95 (8F) & 160 (A0) at least showed no character. I haven't got a tab control to test it on, but they may be worth checking. Otherwise Jim's suggestion seems as if it may take you where you want to go I would think. Good luck anyway.

            PS. I managed a test on a label category. 95 was no good, but 160 seemed to work. Be advised though, I doubt it's very portable/reliable.

            Comment

            • OldBirdman
              Contributor
              • Mar 2007
              • 675

              #7
              Thank you for the replies.
              On my machines, the character 95 (8F) is an 'a' with an accent over it, an extended alphabet character. It shows on a tab as this character, not as a blank.

              The character 160 (A0) is the underscore. It also shows in both tab controls and label controls.

              I have 2 solutions to my initial question:
              1) Start and end each tab caption with a period(.). With a bold font, this gives the control a riveted, or hi-tech appearance.
              2) Use Jim's suggestion as follows:
              Code:
              Private Sub Form_Load()
              Dim i As Integer
              ...
                  'Initialize tab captions - Cannot be done at design time: Access strips trailing blanks
                  For i = 0 To 23
                      If i < 6 Then
                          tabUnits.Pages(i).Caption = Space(7) & Int(i / 6) * 100 + 1 + i Mod 6 & Space(7)
                      Else
                          tabUnits.Pages(i).Caption = Space(5) & Int(i / 6) * 100 + 1 + i Mod 6 & Space(5)
                      End If
                  Next i
                  tabUnits.Pages(24).Caption = "                 Office                "
                  tabUnits.Pages(25).Caption = "               Storage Room                 "
              ...
              End Sub
              Note: All lengths and number of spaces are determined by 'trial-and-error'. The width of the tab control, the font size, the font weight, and the font name all determine how much space the actual characters use.
              In my example, I cannot use 'Tab Fixed Width' because of the 2 un-numbered rooms. Proportional spacing with FontName=Tahoma makes the 2 different space() lengths necessary for room numbers less than 100.

              Comment

              • jimatqsi
                Moderator Top Contributor
                • Oct 2006
                • 1288

                #8
                Steven Lebans created a sample mdb to automatically resize a textbox (or other control) to fit the text that needed to be in it. The exact description from within the routine reads:
                "Returns Control Width & Height needed to display the contents of the Control passed to this function."

                Maybe that has the key to your solution. It uses a lot of API calls and takes the control's font property into consideration when making the calculation. You can find it at


                You could come up with something using that at runtime to calculate the needed size after all captions are known, and then automatically set the tab width property.

                I hope this helps.

                Jim
                Last edited by jimatqsi; Jul 6 '10, 09:53 PM. Reason: typo

                Comment

                • OldBirdman
                  Contributor
                  • Mar 2007
                  • 675

                  #9
                  Thanks Jim.
                  This is a form design problem. I wanted tabs that were larger than Access created by default. I also wanted the tabs to form a logical matrix, room 203 in the same column as 103 & 303.
                  My original post shows what I want. I changed the font size to increase the individual tab's width, but beyond FontSize=14, the text was overpowering.
                  I tried fixed-width tabs, but the 2 non-numbered rooms defeated that approach.
                  I padded the numbers with leading blanks, which works well, but the numbers are not centered on the tabs. So I tried to pad to the right, but Access strips the trailing blanks in Design View.
                  Solution is to assign the tab captions at run-time. Works quite well, thank you. It just takes trial-and-error to balance the number of leading/trailing blanks, the font size, the tab width, and the tabcontrol width.
                  I'm happy with this.

                  Comment

                  Working...