help with converting a user form text box to date format

arey

Board Regular
Joined
Feb 14, 2006
Messages
166
Hi all,


I created a user form and have a text box that should contain the date. When the user opens the form I'd like this cell to display as "mm/dd/yyyy". Indicating to the user that the date should be entered in that format.

Any ideas how I can accomplish this?

I have a similar request for a time field but If I can get the date, im sure i can figure out the time.

Any help would be great.

Thanks in advance.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Like this?

Code:
Private Sub UserForm_Initialize()
    With TextBox1
        .Text = "mm/dd/yyyy"
        .SetFocus
        .SelStart = 0
        .SelLength = Len(.Text)
    End With
End Sub
 
Upvote 0
Forgive me Im really new at creating these forms.

the code I have for the text box right now looks like this...
Private Sub txtDate_Change()
End Sub


Do i simply replace what I have with what you provided?
 
Upvote 0
The code I posted is in the UserForm's Initialize event procedure. So the TextBox is populated when you show the form. I don't think you need any code in the TextBox's Change event procedure.
 
Upvote 0
Thanks a million!

That works great!

Two more questions.

1. I can use the same code for the time, correct"
2. What would I add if i wanted the "/ /" to stay in the text box for the user to add the date?
 
Upvote 0
You can also right-click on the UserForm Toolbox and select Additional Controls, where you should find a reference to the Microsoft Date & Time Picker controls. They're pre-formatted to accept Dates/Times only. The first displays a calendar control, the second a spin box.

HTH,
 
Upvote 0

Forum statistics

Threads
1,216,189
Messages
6,129,411
Members
449,509
Latest member
ajbooisen

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