Can an activeX controle calender holds date of today

  • Thread starter Thread starter Peter Adema
  • Start date Start date
P

Peter Adema

I created an activeX control (calender control 9.0)in a
form.
You can set a default date in this calender.

I want Access to fill in automatically the current date.
How can I do this?
 
Pete,

It takes one line of code to do this, whether you want today's date
defaulted in on all records, or just new ones (that is, if the control is
bound to a table field, in which case you don't want to change existing
dates).
In either case, the code goes to the form's On Current event.
For all records:

Me.ActiveXCtl0 = Date

For new records only:

If Me.NewRecord Then Me.ActiveXCtl0 = Date

Just change ActiveXCtl0 to the actual name of your calendar control.

To paste the code where it belongs: while in form design view, select the
calendar control, display the properties window, select tab Events and put
the cursor next to On Current; click on the little button with the three
dots on the right, and select Code Builder; you will be taken to a VB editor
screen, and the cursor will be between these lines:

Private Sub Form_Current()

End Sub

Just paste the line of code in between, and close the VB window. The trick
is done.

HTH,
Nikos
 
Back
Top