Set DTPickers Data to Todays Date by Default

R

RyanH

I have a Userform with several DTPickers. Next to each DTPicker is a
checkbox. This is how I relate the checkbox and dtpicker, Checkbox1.Value =
DTPicker1.Visible.

How can I set the DTPickers date to todays date when the userform is
intialized? Currently the date is the date I added it to the userform. This
is what I use to get around it.

Sub Userform_Initialize()

' set all dtp controls to todays date,
' if the DTPicker is not visible and you try to set the date you get
an error
For Each dtp In colDueDates
With dtp
If .Visible = False Then
.Visible = True
.Value = Date
.Visible = False
End If
End With
Next dtp
End Sub
 
G

Gord Dibben

Work this into your initialize

Private Sub UserForm_Initialize()
' Check if active cell contains a date. If 'yes' show
' same date on calendar. If 'no' show today's date.
If IsDate(ActiveCell.Value) Then
Calendar1.Value = DateValue(ActiveCell.Value)
Else
Calendar1.Value = Format(Date, "dd-mmm-yy")
End If
End Sub


Gord Dibben MS Excel MVP
 

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