change format of dropdown list in combo box

I

itsyash

For a combo box, I am building a list of dates for the last 365 days
using a loop. This date is in "mm/dd/yyyy" format by default. I want
to display this list in "dd/mmm/yyyy" format when the user clicks on
the drop down.

For this i'm using the code:

Private Sub cmbDateOfTimeLimit_Change()
cmbDateOfTimeLimit.Value = Format(cmbDateOfTimeLimit.Value, "dd/
mmm/yyyy")
End Sub
This is because if I use

cmbDateOfTimeLimit.Value = Format(cmbDateOfTimeLimit.Value, "dd/
mmm/yyyy")
in the userform_initialize() event it does not change anything....

However when i use the code in combobox_change() it displays the date
in "dd/mmm/yyyy" format only after the date is selected. In the drop
down it still shows in the old format.


Can someone plz help me 2 get rid if this issue..

Thanks in advance,
Yash
 
C

Corey

Try the Combobox_Select option instead of _Change

Corey....
For a combo box, I am building a list of dates for the last 365 days
using a loop. This date is in "mm/dd/yyyy" format by default. I want
to display this list in "dd/mmm/yyyy" format when the user clicks on
the drop down.

For this i'm using the code:

Private Sub cmbDateOfTimeLimit_Change()
cmbDateOfTimeLimit.Value = Format(cmbDateOfTimeLimit.Value, "dd/
mmm/yyyy")
End Sub
This is because if I use

cmbDateOfTimeLimit.Value = Format(cmbDateOfTimeLimit.Value, "dd/
mmm/yyyy")
in the userform_initialize() event it does not change anything....

However when i use the code in combobox_change() it displays the date
in "dd/mmm/yyyy" format only after the date is selected. In the drop
down it still shows in the old format.


Can someone plz help me 2 get rid if this issue..

Thanks in advance,
Yash
 
I

itsyash

Try the Combobox_Select option instead of _Change


For a combo box, I am building a list of dates for the last 365 days
using a loop. This date is in "mm/dd/yyyy" format by default. I want
to display this list in "dd/mmm/yyyy" format when the user clicks on
the drop down.

For this i'm using the code:

Private Sub cmbDateOfTimeLimit_Change()
cmbDateOfTimeLimit.Value = Format(cmbDateOfTimeLimit.Value, "dd/
mmm/yyyy")
End Sub
This is because if I use

cmbDateOfTimeLimit.Value = Format(cmbDateOfTimeLimit.Value, "dd/
mmm/yyyy")
in the userform_initialize() event it does not change anything....

However when i use the code in combobox_change() it displays the date
in "dd/mmm/yyyy" format only after the date is selected. In the drop
down it still shows in the old format.

Can someone plz help me 2 get rid if this issue..

Thanks in advance,
Yash

doesn't work :)
 
C

Corey

what about using this in the Combobox1_Select :
Combobox1.value = Format(Combobox1.value,"dd/mmmm/yyyy") ?


Try the Combobox_Select option instead of _Change

message
For a combo box, I am building a list of dates for the last 365 days
using a loop. This date is in "mm/dd/yyyy" format by default. I want
to display this list in "dd/mmm/yyyy" format when the user clicks on
the drop down.

For this i'm using the code:

Private Sub cmbDateOfTimeLimit_Change()
cmbDateOfTimeLimit.Value = Format(cmbDateOfTimeLimit.Value, "dd/
mmm/yyyy")
End Sub
This is because if I use

cmbDateOfTimeLimit.Value = Format(cmbDateOfTimeLimit.Value, "dd/
mmm/yyyy")
in the userform_initialize() event it does not change anything....

However when i use the code in combobox_change() it displays the date
in "dd/mmm/yyyy" format only after the date is selected. In the drop
down it still shows in the old format.

Can someone plz help me 2 get rid if this issue..

Thanks in advance,
Yash

doesn't work :)
 
R

Rick Rothstein \(MVP - VB\)

doesn't work :)

Give this UserForm Initialize event code a try...

Private Sub UserForm_Initialize()
Dim X As Date
For X = Now - 365 To Now
ComboBox1.AddItem Format$(X, "dd/mmm/yyyy")
Next
End Sub

Nothing for you to do after this... the list will display as you wanted.

Rick
 
R

Rick Rothstein \(MVP - VB\)

doesn't work :)
Give this UserForm Initialize event code a try...

Private Sub UserForm_Initialize()
Dim X As Date
For X = Now - 365 To Now
ComboBox1.AddItem Format$(X, "dd/mmm/yyyy")
Next
End Sub

Nothing for you to do after this... the list will display as you wanted.

Of course, you would use your ComboBox's Name instead of ComboBox1 like I
did.

Rick
 

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