Cannot set value of calendar control in Access 97

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?
 
V

Van T. Dinh

Calendar Control has the Today Method that sets the Value to today's date.
Try:

actx_FromDate.Today
actx_ToDate.Today
 
P

PC Datasheet

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()
 
K

Kirk Speen

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...
 
K

Kirk Speen

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?
 
V

Van T. Dinh

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).
 
K

Kirk Speen

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.
 

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