Solved

Access 2003: Format/Align/Middle?

Posted on 2006-06-14
21
516 Views
Last Modified: 2008-03-10
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
Comment
Question by:cepes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 7
  • 2
  • +2
21 Comments
 
LVL 14

Expert Comment

by:JohnK813
ID: 16902825
I'm not sure if this is what you want, but try changing "Text Align" from 'General' to 'Center.'
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16902832
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
 

Author Comment

by:cepes
ID: 16902911
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:cepes
ID: 16903118
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
 
LVL 65

Expert Comment

by:rockiroads
ID: 16903469
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
 

Author Comment

by:cepes
ID: 16903524
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
 
LVL 15

Expert Comment

by:cquinn
ID: 16903604
The VBA will not run in design mode - you would need to write an add-in to do this
0
 
LVL 58

Expert Comment

by:harfang
ID: 16912559
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
 

Author Comment

by:cepes
ID: 16912644
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
 
LVL 58

Expert Comment

by:harfang
ID: 16912740
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
 

Author Comment

by:cepes
ID: 16912787
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
 
LVL 58

Accepted Solution

by:
harfang earned 500 total points
ID: 16912857
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
 

Author Comment

by:cepes
ID: 16912965
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
 

Author Comment

by:cepes
ID: 16912979
I take it all back.  It works great; just a glitch before with one two boxes.

Thank you so much!!!

Charlie
0
 
LVL 58

Expert Comment

by:harfang
ID: 16912986
Please define: "center just where they are", using simple math and the .Width and .Left measurements.
(°v°)
0
 
LVL 58

Expert Comment

by:harfang
ID: 16912995
Oh, ok. Good luck then!
(°v°)
0
 

Author Comment

by:cepes
ID: 16913053
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
 
LVL 58

Expert Comment

by:harfang
ID: 16913127
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
 

Author Comment

by:cepes
ID: 16913161
Sorry...  Module or Class module?

Charlie
0
 
LVL 58

Expert Comment

by:harfang
ID: 16913181
Just Module. Class modules need to be instanciated (like forms and reports) before they can be used.
(°v°)
0
 

Author Comment

by:cepes
ID: 16913208
Got it.  Thanks-
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question