set a value with VBA in the control date picker

  • Thread starter Thread starter Kon
  • Start date Start date
Kon said:
Can I set a value to the control date picker if yes how?

Yes, if this is about the DTPicker ActiveX control. Good practise is to use
an object variable in the form module which will be set during the form's
load event. Then you'll get full editing support through Intellisense.
Optionally is the use of the keyword WithEvents for having access to the
controls event procedures via the object variable.

Option Compare Database
Option Explicit

Private WithEvents m_objDTP As MSComCtl2.DTPicker

Private Sub Form_Load()
Set m_objDTP = Me!YourControlName

' set the date one month back
m_objDTP.Value = DateAdd("m", -1, Date)
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set m_objDTP = Nothing
End Sub
 
Back
Top