default value

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

Dan Artuso

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"""
 
R

Ran BD

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

Dan Artuso

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 & """"
 
D

Dan Artuso

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

Ran BD

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

Dan Artuso

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

Ran BD

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

Guest

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.
 

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