Userform Date Picker textbox will not select current date

fonk

New Member
Joined
Mar 30, 2009
Messages
49
Hi all,
I have userform with date pickers and have text boxes overlaid on these, when I select todays date from the date picker it does not display the current date in the text box (I have 8 date pickers on the userform). If I select another date then reselect the current date it works. It has occasionally worked but trying to figure out why.
Below is the code for populating the text box from the Date Picker.
Code:
Private Sub DTPicker1_Change()
TextBox1.Value = DTPicker1.Value
End Sub
The initialize userform code uses the following to format and set the textbox
Code:
TextBox1.Value = Format(Date, "dd-mmm-yy")
TextBox1.Value = ""

Cheers, Dave
Windows 7 with Excel 2010
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I don't have XL2010 to test on, but you're not changing it the first time. Look into another event to cause the code to fire. Maybe a mousemove or.......I don't know. As I said, I don't have 2010 to test on, but it seems like there should be SOME event that would create a more instant change of the textbox
 
Upvote 0
Hi jproffer,
Thanks, I'm always learning, I'll try adding an event & see if that works. Will let you know the result.

Cheers, Dave
 
Upvote 0
I don't know that you can "add" an event. But where your code says

Code:
DTPicker1_Change

Select "DTPicker1" in the left dropdown list at the top of the VBE, then look in the right drop down list and see if any other event would be better.
 
Upvote 0
This code
Code:
TextBox1.Value = Format(Date, "dd-mmm-yy")
TextBox1.Value = ""
serves no purpose in an Initialize event, unless you had saved a value in the textbox at design time, in which case you only need the second line.

I would guess that the DTPicker is defaulting to today, so it's not a Change if you select it. Perhaps the Exit event would be better.
 
Upvote 0
jproffer & rorya,
Thanks for taking the time and for your suggestions, the exit works for what I want, just need to click off the text box for it to display and I can't see that being a problem.
Also got rid of the format line of code from the Initialize event and will put that elsewhere to format the textboxes.
Cheers, Dave

Still learning, still making mistakes but at least I know where to go for help.
 
Upvote 0
You can't apply a format to a textbox. You have to format the value every time you enter one.
 
Upvote 0
jproffer & rorya,
Below is the solution that seems to sort the problem for me with the formatting of the TextBox from the Date Picker.

Code:
Private Sub DTPicker1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox1.Value = DTPicker1.Value
strDate = Format(DTPicker1, "dd-mmm-yy")
        TextBox1 = strDate
End Sub

Thanks again, Dave
 
Upvote 0

Forum statistics

Threads
1,215,642
Messages
6,125,989
Members
449,277
Latest member
Fanamos298

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