On get focus event

  • Thread starter Thread starter Rani
  • Start date Start date
R

Rani

I would like to display the current date while the field is getting focus,

imp using me.defaultvalue.fieldname = date

and this is what I'm getting in return
30/12/1899 00:00:24

any idea ?
 
Rani said:
I would like to display the current date while the field is getting
focus,

I don't know what you mean by this. What did the field display before
it got the focus? What should it display after it gets the focus?
imp using me.defaultvalue.fieldname = date

This is not valid syntax and would never compile. Please post the
actual code you're using.

If you're trying to do something with the DefaultValue property, could
it be that you need no code at all, but just to set the field or
control's Default Value property to

Date()
and this is what I'm getting in return
30/12/1899 00:00:24

That's pretty close to a zero value, for a date. Probably the date
field has a default value of zero. But that's an odd default value for
a date field. Is this in fact a field of type date/time (as defined in
the table design view) or is it a number field to that you're only
*formatting* as a date?
 
the field isn't displaying anything before it is getting focus, and should
display today's date after it is getting focus.
the code I'm using is :Me.StartDate.DefaultValue = Date
and the reason I don't want to use the default value property is that I want
the value to appear only when the field is getting focus and not before.

thanks
 
Rani,

Try putting this into the GotFocus event of your control
StartDate...

Me!StartDate = Date()
 
Rani said:
the field isn't displaying anything before it is getting focus, and
should display today's date after it is getting focus.
the code I'm using is :Me.StartDate.DefaultValue = Date
and the reason I don't want to use the default value property is that
I want the value to appear only when the field is getting focus and
not before.

thanks

I'm not sure how well this is going to work, but I think I see what's
wrong with your code. The DefaultValue property is a String property,
which for a date field must be set to a string representation of the
default date value as a *date literal*. Try this:

Me.StartDate.DefaultValue = "#" & Date & "#"
 
I don't think it is going to work with DefaultValue since DefaultValue works
only on NewRec and (I am pretty sure) that the DefaultValue got to be set
*before* the NewRec becomes the current "Record".

Use Gary's method but remember that with Gary's assignment statement, the
Forn's Dirty Property is True so if the user backs out, you need to undo the
Form.
 
Van T. Dinh said:
I don't think it is going to work with DefaultValue since
DefaultValue works only on NewRec and (I am pretty sure) that the
DefaultValue got to be set *before* the NewRec becomes the current
"Record".

That's what I thought, too, but I tried it and it worked -- though only,
as you say, for the new record. But I'm guessing (and only guessing)
that this is about the new record, not existing ones.
 
Thanks, Dirk

Interesting. Logically, default values should be available just before the
Form moves to the NewRec so that Access can assign Controls / Fields with
the default values, NOT after the NewRec has become the CurrentRecord.

Cheers
Van
 
Van T. Dinh said:
Thanks, Dirk

Interesting. Logically, default values should be available just
before the Form moves to the NewRec so that Access can assign
Controls / Fields with the default values, NOT after the NewRec has
become the CurrentRecord.

I'm not sure how default values are handled, but I think it's more
complicated than I originally thought.
 
Back
Top