• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 520
  • Last Modified:

Access 2003: Format/Align/Middle?

Hi:
In making forms, I often want to align boxes or text by "middle", not necessarily left or right, top or bottom.  

Is there an easy way to do this? Am I just missing the command on the menu?

Thanks.

Charlie
0
cepes
Asked:
cepes
  • 10
  • 7
  • 2
  • +2
1 Solution
 
JohnK813Commented:
I'm not sure if this is what you want, but try changing "Text Align" from 'General' to 'Center.'
0
 
rockiroadsCommented:
There is formatting available

Format/Align

but there is no Middle. Well Ive not seen any.

What u could do is display the grid and manually move your controls, using the grid to help you
0
 
cepesAuthor Commented:
That's new to me and that's great but I gues I was looking for a menu command which would save me from going into Properties all the time.  Maybe I could create a macro and assign it.

Charlie
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
cepesAuthor Commented:
Well, I forgot there's no Macro Recorder in Access.  

Can someone help write the VBA for a macro to Center all selected text boxes?

Thanks

Charlie
0
 
rockiroadsCommented:
Having a guess, I guess u could start off with one control
then base everything under that

Questions -

do u want it go horizontally or vertically?

what about labels that go alongside textboxes

how do u know which labels are for which textboxes?

Think about what controls u want to centre, where u want to base them from



0
 
cepesAuthor Commented:
My primary need is to center text boxes vertically:
    so
   they
  line up
   well

I do not need to center horizontally.

Labels that accompany text boxes:  Once I align them "over" the text box, yes, I'd like to include them too.

"how do u know which labels are for which textboxes?"  I would select them

I think that's it.    
0
 
cquinnCommented:
The VBA will not run in design mode - you would need to write an add-in to do this
0
 
harfangCommented:
Hello cepes

I believe you simply want the formatting toolbar: "view / toolbars / formatting (forms/reports)". On it, there is a nice friendly button called "center".

If you wish to create a VB function for that, lookup the following topics in Help:

    Screen.ActiveForm
    <form object>.CurrentView
    <control object>.InSelection

Cheers!
(°v°)
0
 
cepesAuthor Commented:
harfang:
That "Center" command is for text I think, not for aligning the center of the selecting text boxes.  I may have steered you wrong by stacking the text above like this:
   so
   they
  line up
   well

I'm looking for a command that will vertically align the centers of selected text boxes or control boxes.

Charlie
0
 
harfangCommented:
Ah. I see.

     [so]
             [they]
   [line up]
     [well]

1) select, right-click, choose "align / left"

   [so]
   [they]
   [line up]
   [well]

2) right-click, choose "size / to widest"

   [so     ]
   [they  ]
   [line up]
   [well    ]

3) click "center" from the toolbar:

   [   so  ]
   [ they ]
   [line up]
   [  well  ]

4) if these are labels, and you really want to display borders around them, double-click any one of the resize handles or right-click and choose "size / to fit". I don't really see the point, though.

      [so]
    [they]
   [line up]
     [well]

Have fun!
(°v°)
0
 
cepesAuthor Commented:
harfang:

I'm still at a loss.  The suggestion:

3) click "center" from the toolbar:

   [   so  ]
   [ they ]
   [line up]
   [  well  ]

only lines up the text in the boxes, not the boxes themselves.  Am I missing something?  When I highlight more than one box, the center button grays out.

Charlie
0
 
harfangCommented:
Well, yes, it centers the text. I'm not sure I follow your desired layout, it seems rather odd. You actually want to center controls?

Attach this to a custom toolbar button (on action: = AlignCenterControls())


Function AlignCenterControls()

    Dim ctl As Control
    Dim lngCenter As Long

On Error GoTo Error_Label

    For Each ctl In Screen.ActiveForm.Controls
        If ctl.InSelection Then _
            ctl.Left = (Screen.ActiveForm.Width - ctl.Width) / 2
    Next ctl
    Exit Function
   
Error_Label:
    MsgBox Err.Description
    Err.Clear
End Function


or do you want to "align center" based on the first selected control?


Function AlignCenterControlsBelow()

    Dim ctl As Control
    Dim lngCenter As Long

On Error GoTo Error_Label

    For Each ctl In Screen.ActiveForm.Controls
        If ctl.InSelection Then
            If lngCenter = 0 Then
                lngCenter = ctl.Left + ctl.Width / 2
            ElseIf lngCenter > ctl.Width / 2 Then
                ctl.Left = lngCenter - ctl.Width / 2
            Else: ctl.Left = 0
            End If
        End If
    Next ctl
    Exit Function
   
Error_Label:
    MsgBox Err.Description
    Err.Clear
End Function


(°v°)
0
 
cepesAuthor Commented:
So close!!!!

This works great but similar to Align Right in which the command merely aligns all the right edges in line, can this center all the "boxes jst where they are?  With your code, the boxes become centered on the entire page.

Charlie
0
 
cepesAuthor Commented:
I take it all back.  It works great; just a glitch before with one two boxes.

Thank you so much!!!

Charlie
0
 
harfangCommented:
Please define: "center just where they are", using simple math and the .Width and .Left measurements.
(°v°)
0
 
harfangCommented:
Oh, ok. Good luck then!
(°v°)
0
 
cepesAuthor Commented:
One more question.... How do I save this module for all forms, not just the form I'm working on?  In other words, local vs. global?

Charlie
0
 
harfangCommented:
Place the function in a standard module (modules tab, [New]). This will be available for the entire database. Call it something like "basToolbarFunctions", *not* the name of the function it contains.

Cheers!
(°v°)
0
 
cepesAuthor Commented:
Sorry...  Module or Class module?

Charlie
0
 
harfangCommented:
Just Module. Class modules need to be instanciated (like forms and reports) before they can be used.
(°v°)
0
 
cepesAuthor Commented:
Got it.  Thanks-
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 10
  • 7
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now