How to set the DTPicker default value thru VBA

G

Gabriel

Is there a way set/change the value of Date Time Picker ActiveX Control
(MSComCtl2.DTPicker.2) thru VBA ?

Gabriel
 
N

Nikos Yannacopoulos

Gabriel,

You can use the form's On Open event (or whichever even suits your needs) to
run a line of code like:

Me.ActivexCtl0 = Date()

(where I have assumed the control's name to be ActivexCtl0 - change to the
actual one) to set it to the current date when the form opens. This will
work nicely on an unbound control.
If, however, the cotrol is bound to a table field, then you need to only set
it to the current date (or whichever calculated date) only when going to a
new record. In that case, you should use the form's On Current event, with
code like:

If Me.NewRecord Then
Me.ActivexCtl0 = Date()
End If

Note: the DTPicker control has a time part as well; if you also need to
record the time in the day, use function Now() instead of Date().

HTH,
Nikos
 

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