default value

  • Thread starter Thread starter Ran BD
  • Start date Start date
R

Ran BD

Hi guys

I’ve set a default value to a field in a form, but I want the value to
appear only when the field is getting focus.

Any ideas?
 
Hi,
You'll have to do this from code.
Remove the value from the property sheet and put
this code in the Got Focus event of the text box:

Me.yourControl.DefaultValue = """whateverYouWantHere"""
 
Dan Thanks for your help.

What i was trying to do was to declare the default value as date$()

In the get focus property I’ve entered me.Purchesed_Date.DefaultValue =
Date$()

And i received an unrecognized macro error from access.



Any idea?
 
Hi,
The default value has to appear as it would on the
property sheet. So, were you to enter a date there it
would look like this:
"10/18/2003"

The quotes have to be a part of the value, so...
me.Purchesed_Date.DefaultValue = """" & Date & """"
 
Hi,
You're not entering this directly on the property sheet, are you?
That will not work.
You have to click on the ellipsis (...) beside the event property
and enter it in the code module.
 
Dan thanks this is working fine, though i have another question on the
subject, assuming the object will get focus again, will it work as well ?

iv'e tried it and in the second time the value isn't re-appearing

any idea ?
 
Hi,
I'm not sure what you mean. The default value will appear as soon
as it gets the focus (this will only happen on new records).
If you change the value or delete it, it will not re-appear.
That's how a default value works.
 
thanks dan.
Dan Artuso said:
Hi,
I'm not sure what you mean. The default value will appear as soon
as it gets the focus (this will only happen on new records).
If you change the value or delete it, it will not re-appear.
That's how a default value works.
 
hey.

Instead of giving the field a default value use the 'On
Got Focus' event.

Private Sub FieldName_GotFocus()
me.FieldName = xxx
End Sub

Hope this helps.
 
Back
Top