Solved

Access 2003: Format/Align/Middle?

Posted on 2006-06-14
21
512 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
  • 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
 

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now