UserForm - TextBox date value from ListBox not showing has a date

TheSardOz

New Member
Joined
Nov 30, 2020
Messages
26
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have created a userform to add data to a sheet.
I have a function to edit the data that I am entering, in case I made a mistake before I save it.
To display the data from the ListBox back to the TextBox to be edited I use The DblClick event and this code : Me.TextBox_Date = Me.ListBox_Data_Drop.List(Me.ListBox_Data_Drop.ListIndex, 11)
but the date display as the number value
1648151718354.png


I have tried to add this formatting on the Form Initialize but it do not work in this case. 'TextBox_Date.Text = Format(Date, "d/mm/yyyy h:mm AM")

I hope someone will help thank you in advance
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
One cannot format a text box in a persistent way like cells on a worksheet can be formatted.
So eacht time the value of a text box changes and we need a certain format, the code needs to take that into account.

Try replacing this
Rich (BB code):
    Me.TextBox_Date = Me.ListBox_Data_Drop.List(Me.ListBox_Data_Drop.ListIndex, 11)


with this
VBA Code:
    Me.TextBox_Date.Value = VBA.Format(Me.ListBox_Data_Drop.List(Me.ListBox_Data_Drop.ListIndex, 11), "d/mm/yyyy h:mm AM")
 
Upvote 0
One cannot format a text box in a persistent way like cells on a worksheet can be formatted.
So eacht time the value of a text box changes and we need a certain format, the code needs to take that into account.

Try replacing this
Rich (BB code):
    Me.TextBox_Date = Me.ListBox_Data_Drop.List(Me.ListBox_Data_Drop.ListIndex, 11)


with this
VBA Code:
    Me.TextBox_Date.Value = VBA.Format(Me.ListBox_Data_Drop.List(Me.ListBox_Data_Drop.ListIndex, 11), "d/mm/yyyy h:mm AM")
Thank you very much ... it did the job just right
 
Upvote 0
One cannot format a text box in a persistent way like cells on a worksheet can be formatted.
So eacht time the value of a text box changes and we need a certain format, the code needs to take that into account.

Try replacing this
Rich (BB code):
    Me.TextBox_Date = Me.ListBox_Data_Drop.List(Me.ListBox_Data_Drop.ListIndex, 11)


with this
VBA Code:
    Me.TextBox_Date.Value = VBA.Format(Me.ListBox_Data_Drop.List(Me.ListBox_Data_Drop.ListIndex, 11), "d/mm/yyyy h:mm AM")
Just the AM shows has A10 ( is showing the corresponding number of M?)
1648157476302.png
 
Upvote 0
I see, I've overlooked a tiny detail, the code should have been:
Rich (BB code):
Me.TextBox_Date.Value = VBA.Format(Me.ListBox_Data_Drop.List(Me.ListBox_Data_Drop.ListIndex, 11), "d/mm/yyyy h:mm AM/PM")
 
Upvote 0
I see, I've overlooked a tiny detail, the code should have been:
Rich (BB code):
Me.TextBox_Date.Value = VBA.Format(Me.ListBox_Data_Drop.List(Me.ListBox_Data_Drop.ListIndex, 11), "d/mm/yyyy h:mm AM/PM")
Thank you once again!
 
Upvote 0

Forum statistics

Threads
1,215,831
Messages
6,127,137
Members
449,361
Latest member
VBquery757

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top