the calendar control!?

  • Thread starter Thread starter Jerome
  • Start date Start date
J

Jerome

The calendar control in Access 2003 is driving me nuts ...

How can I tell this control to automatically select the current date
when the form is opened?

I tried it with:

Me.MyCal.Value=Now()

But that doesn't work. The debugger tells me I can't assign a value!?

Thanks a lot!

Jerome
 
Try assigning the Default Value. It will only affect new records, but that's
all you should want, really.

If not, can you give some more info...

HTH
Piers
 
Be careful with the use of "now()". Now() returns BOTH time + date
information. if you are stuffing "now()" into a date field, then you can
make a real mess of things, as now all your dates will include a time stamp
also. (this means a simple where InvoiceDate = #05/24/2005# will fail, since
you also will have to include the time part!!

So, two suggestions;

use date, and also make sure you use the on-load event, as the on -open
event of the form is too soon (the on open event has a cancel feature..and
thus is where code can test for certain things..and NOT load the form).
After the on-open occurs, then the on-load event occurs. The on-load is
where you can put setup code, and initialize fields etc. So, keep in mind
the difference between on-open (too soon to modify data fields), and the
on-load event.

So, in the on-load event, you should be able to go:

Me.MyCalValue = Date
 
Jerome,

My penny's worth:

1. As already advised by Albert, use Date(), not Now()

2. Use the form's On Current event; it fires on every record, so if you
combine it with a check for the new record event you can default in the
current date on new records only, leaving existing ones unchanged as you
browse through them, like Piers suggested you should. The code would
look something like:

Private Sub Form_Current()
If Me.NewRecord Then Me.MyCal = Date()
End Sub

HTH,
Nikos
 
Back
Top