We have a standard Access listbox with multiple columns. Is there a way to have integer or currency columns right aligned?
7 Answers
Depending on your query the alignment of a column will be inherited from the underlying table. So, go to the table, select the column, center/right/left align it, and then your textbox should have the same alignment. This won't work for calculated fields, but it should for most others.

- 121
- 2
- 9
-
Solved my problem for aligning data from different list boxes from multiple tables on one form. Thanks! Works in Access 2013 on calculated fields, too. – Terri Sep 13 '15 at 14:47
-
Best solution for me! If you need to align simple calculations that are based on other fields in the same table, you can also add calculated columns to the table and align those. Then use the pre-calculated fields in the listbox and their alignment will be inherited as well. – Jörg Brenninkmeyer Dec 17 '16 at 16:39
No. The closest I've seen is JustiCombo which is a database containing functions to center and right justify data for List and Combo Boxes. It can use proportional fonts by analysing the font attributes and character widths. It too stuffs spaces in the front of the fields to make the data appear centre/right justified. It did the best it could but you could see a few jaggies. But then maybe I was being too critical.

- 7,850
- 1
- 22
- 27
-
Actually it does work reasonably well. And it's quite interesting reading the API code figuring out how Stephen coded it. – Tony Toews Oct 13 '10 at 23:04
-
i have total respect for Stephen Lebans and have used his stuff in the past. but in my case right aligned columns was a nice-to-have, not something i want to go out to a third party control for. thanks for the info though. the api would be interesting sure, at a time when i'm not up against a deadline. – hawbsl Oct 14 '10 at 08:08
As far as I'm aware, not in the traditional sense, no. I believe there are some third-party products that might be able to do this, but there's no native ColumnAlignment
properties for listboxes in any versions I've used (haven't used Access 2007, though, for what it's worth).
Depending on how you are loading the listbox, you could use a fixed-width font (such as Courier) and left-pad your numbers with the appropriate number of spaces, to emulate right-alignment. It's not ideal, but it may be worth a shot.

- 32,008
- 25
- 109
- 114
- Convert the listbox to combobox
- Make the combobox that you converted right alignment
- Convert it again to listbox

- 90,663
- 31
- 146
- 203

- 21
- 1
In VB it is:
Format(Format("10000", "0.00%"), "@@@@@@@@@@")
where the number of "@"s are the width of the field in which to right justify the string.
In VBA you can use:
xFormat(Format("10000", "0.00%"), "@@@@@@@@@@")
where
Function xFormat(ByVal s, ByVal width As String) As String
Dim temp As String
Dim deltaL As Integer
deltaL = Len(width) - Len(s)
If deltaL > 0 Then
temp = Space(deltaL) & s
Else
temp = s
End If
xFormat = temp
End Function

- 8,016
- 6
- 40
- 62

- 21
- 1
I use the following:
Public Function Paddy_Boy(ByVal s As String) As String
Const FillChar As Integer = 160 ' the key to success; this is an unpaddable space
Const MAX_CHARS As Integer = 12 ' the max # of chars in the target column; you could pass this as an arg, but obviously it depends on the data. and i can only get it to work nicely using Courier New.
Dim i As Integer
Dim l As Integer
Dim Z As String
Z = "Paddy_Boy"
Paddy_Boy = s
On Error GoTo Err_Sub
l = Len(s)
i = MAX_CHARS
While (i > l)
Paddy_Boy = Chr(FillChar) & Paddy_Boy
i = i - 1
Wend
Exit_Sub:
Exit Function
Err_Sub:
MsgBox Err.Number & ": " & Err.Description, vbCritical, Z
GoTo Exit_Sub
End Function

- 1