Connecting Tech Pros Worldwide Forums | Help | Site Map

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

deko
Guest
 
Posts: n/a
#1: Nov 13 '05
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
Guest
 
Posts: n/a
#2: Nov 13 '05

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


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" <deko@hotmail.com> wrote in message
news:2jLTd.754$C47.720@newssvr14.news.prodigy.com. ..[color=blue]
> 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...
>
>[/color]


Justin Hoffman
Guest
 
Posts: n/a
#3: Nov 13 '05

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



"deko" <deko@hotmail.com> wrote in message
news:2jLTd.754$C47.720@newssvr14.news.prodigy.com. ..[color=blue]
> 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...[/color]


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.


deko
Guest
 
Posts: n/a
#4: Nov 13 '05

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


> No, you can only make it stick if you change the value in design view of
the[color=blue]
> 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.[/color]

I see. Thanks for the tip.


deko
Guest
 
Posts: n/a
#5: Nov 13 '05

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


> Ken Snell's answer describes the problem well, but if you are looking for
a[color=blue]
> 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[/color]
text )[color=blue]
> file.[/color]

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.


deko
Guest
 
Posts: n/a
#6: Nov 13 '05

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


> The table is your best bet here, deko. The problem with using a[color=blue]
> 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.[/color]

10-4. Thanks for the tip.


Closed Thread