Display Dates in listbox

  • Thread starter Dale_Fye via AccessMonster.com
  • Start date
D

Dale_Fye via AccessMonster.com

I'm trying to display a couple of columns in a listbox, including a column of
dates, in format mm/dd/yyyy.

However, in the list the leading number on the month is getting dropped, and
they are not right aligned. Anybody have a trick for formatting dates right
aligned in a listbox?
 
L

Linq Adams via AccessMonster.com

For maintaining the leading zeros, you need to make a query to base your
ListBox off of, then create a calculated field in the query like this:

FormatYourDate: Format([YourDate],"mm/dd/yyyy")

Now, base your ListBox on this query, using FormatYourDate instead of
YourDate as one of the fields.

I know of no way to align the date to the right in a ListBox, but maybe
someone else will. I suspect that the ListBox treats all fields as Text.
 
S

Stuart McCall

Dale_Fye via AccessMonster.com said:
I'm trying to display a couple of columns in a listbox, including a column
of
dates, in format mm/dd/yyyy.

However, in the list the leading number on the month is getting dropped,
and
they are not right aligned. Anybody have a trick for formatting dates
right
aligned in a listbox?

You can try this routine, which while its a bit of a kludge, will do the
trick.

Public Function PadFormat(Num, Fmt, Max) As String
Dim ctr As Boolean
Dim f$, l&
'
If Max < 0 Then
Max = Abs(Max)
ctr = True
End If
If Len(Num & "") > 0 Then
f = Format(Num, Fmt)
l = Max - Len(f)
If ctr Then l = l \ 2
If l < 0 Then
PadFormat = f
Else
PadFormat = Space$(l * 2 + (1 And Num < 0)) & f
End If
End If
End Function

Use it as an expression in the query used to fill the list:

=PadFormat(MyDate, "yyyy/mm/dd", 10)

The number 10 is a guesstimate of the number of numeric chars will fit the
column. You play with this number till it works ok.

The 'algorithm' relies on the fact that in most fonts the space char and the
hyphen both occupy 50% of the space of the other numeric chars.

Hope it works for you.
 
P

Peter Hibbs

Stephen Lebans has code to right justify text in a List box at :-
http://www.lebans.com/toc.htm
It's in the List & Combo Controls section and it's called
justification.zip.

Not sure if it will do what you want though.

Peter Hibbs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top