By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,043 Members | 1,215 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,043 IT Pros & Developers. It's quick & easy.

Set DefaultValue of Textbox with VBA - why doesn't it stick?

P: n/a
If I set the DefaultValue of a Textbox in the properties sheet of the
control, it sticks after I close and reopen the form. But if I try to set
it with code:

Me!txtPath.DefaultValue = Chr(34) & Me!txtPath & Chr(34)

The Textbox reverts back to blank after I close and reopen the form. Am I
missing something? The help file says it's read/write...
Nov 13 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
No, you can only make it stick if you change the value in design view of the
form and then save the form. And your code doesn't open the form in design
view.

The property is "read/write", which is why you can change its value while
the form is open. But changing a value does not save the value.

--

Ken Snell
<MS ACCESS MVP>
"deko" <de**@hotmail.com> wrote in message
news:2j***************@newssvr14.news.prodigy.com. ..
If I set the DefaultValue of a Textbox in the properties sheet of the
control, it sticks after I close and reopen the form. But if I try to set
it with code:

Me!txtPath.DefaultValue = Chr(34) & Me!txtPath & Chr(34)

The Textbox reverts back to blank after I close and reopen the form. Am I
missing something? The help file says it's read/write...

Nov 13 '05 #2

P: n/a

"deko" <de**@hotmail.com> wrote in message
news:2j***************@newssvr14.news.prodigy.com. ..
If I set the DefaultValue of a Textbox in the properties sheet of the
control, it sticks after I close and reopen the form. But if I try to set
it with code:

Me!txtPath.DefaultValue = Chr(34) & Me!txtPath & Chr(34)

The Textbox reverts back to blank after I close and reopen the form. Am I
missing something? The help file says it's read/write...

Ken Snell's answer describes the problem well, but if you are looking for a
solution to this, there are a number of options - you just need to decide
where to store this setting. Ideas include a registry entry, a local
settings table, a custom property of the form, an ini (or other plain text )
file.
Nov 13 '05 #3

P: n/a
> No, you can only make it stick if you change the value in design view of
the
form and then save the form. And your code doesn't open the form in design
view.

The property is "read/write", which is why you can change its value while
the form is open. But changing a value does not save the value.


I see. Thanks for the tip.
Nov 13 '05 #4

P: n/a
> Ken Snell's answer describes the problem well, but if you are looking for
a
solution to this, there are a number of options - you just need to decide
where to store this setting. Ideas include a registry entry, a local
settings table, a custom property of the form, an ini (or other plain text ) file.


I tried Me.Tag, but apparently that works the same as DefaultValue. I've
done other databases with a settings table, but with this one it's only one
string. Still, it saves the user a lot of work - otherwise he has to
navigate and drill into the directory structure to repopulate the path
variable each time. A custom form property sound interesting. Are there
any concerns with different versions/service packs? The users in this shop
are some of the worst.
Nov 13 '05 #5

P: n/a
> The table is your best bet here, deko. The problem with using a
custom form property is the same as with any other change to the form,
you have to allow the users to change the form when they close it.
Which can cause other problems.


10-4. Thanks for the tip.
Nov 13 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.