DTPicker default value

Markus_87

New Member
Joined
Mar 29, 2011
Messages
12
Hello again ppl,

Need to be able to set the default value of the dtpicker to always show the current date on opening. and this date needs to be automatically put in a textbox (textbox 28) without the user having to choose from the calender.

Previously had the following code for the textbox

Private Sub DTPicker1_Change()
TextBox28.Value = DTPicker1.Value
unbound_ctrl_Date = DTPicker1.Value
End Sub

But the user still has to choose from the calender before the date is displayed in the textbox. :(

Any help appreciated
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi,

Set the values in the userform_initialize event. Something like this:
Code:
Private Sub UserForm_Initialize()
    DTPicker1.Value = Date
    unbound_ctrl_date = Format(Date, "dd/mm/yyyy")
End Sub
 
Upvote 0
Hi Colin,

Sorry i might not have explained properly as i'm fairly new to this.

The DTpicker is in a dropdown box and although it knows what todays date is you have to go in to the calender and choose the date before it displays it in the dropdown. if that makes sense?

I then want the date displayed in the dropdown to automatically be shown in Textbox 28 when the user opens the form. and not (as i currently have it displayed there once they've opened the calender and clicked)

Many thanks
 
Upvote 0
Not entirely sure this will work, but try it:

In your userform initialize stage

Code:
TextBox28.Value = date
(Therefore the textbox will always display today's date)

However, if there is the possibility that the date you want isn't today's date, leave your original code of:

Code:
Private Sub DTPicker1_Change()
TextBox28.Value = DTPicker1.Value
unbound_ctrl_Date = DTPicker1.Value
End Sub

That way if they happen to change the date away from today, it will still update appropriately.
 
Upvote 0

Forum statistics

Threads
1,224,534
Messages
6,179,390
Members
452,909
Latest member
VickiS

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