Cannot set value of calendar control in Access 97

  • Thread starter Thread starter Kirk Speen
  • Start date Start date
K

Kirk Speen

Hi,

I have a form that has two calendar controls. I want to
set the initial values of these to today's date. Seems
simple enough, but the code:

'Set the calendar controls to today's date
actx_FromDate.Value = now()
actx_ToDate.Value = now()

seems to have no effect on my calendars at all & they keep
the default value set in the properties sheet.

Can anyone tell me what I'm doing wrong?
 
Calendar Control has the Today Method that sets the Value to today's date.
Try:

actx_FromDate.Today
actx_ToDate.Today
 
Kirk,

Now() returns both the current date and the current time. A calendar does not
keep time - that's the reason your code does not work. You need to use the
Date() function.

actx_FromDate.Value = Date()
actx_ToDate.Value = Date()
 
Thanks for the replies, guys.

I tried both using the Date function to set the date:

actx_FromDate.Value = Date()
actx_ToDate.Value = Date()

& also the Today method of the calendar control:

actx_FromDate.Today
actx_ToDate.Today

Both these approaches are coded in the Form_Open event,
but neither seem to have any effect on the controls. I'm
sure I'm missing something, but I'm not sure what...
 
OK, now I tried using each of the methods, including using
Now() to set today's date on the calendar controls from a
command button on the form & they all work!

I'm coming to the conclusion that the calendar control
reads its default values after the form opens.

Can anyone shed any light?
 
Not sure about A97 but the Today Method works in the Form_Open Event in A2K.
Try the Today Method in Load Event.

If you want to set the Value to Date() then use the Form_Current Event
(tested in A2K also).
 
It works OK in the load event in A97. Thanks, Van.

Not sure why it doesn't work in the open event, but hey ho!

Cheers.
 
Back
Top