Me.TxtBox.DefaultValue

jguscs

Registered User.
Local time
Today, 07:10
Joined
Jun 23, 2003
Messages
148
I've read the Access Help on how to set the default value of a an unbound text box to a default value:
Me.TxtBox.DefaultValue = """NULL"""

I want to be able to set the default value of the text box to a string variable, but it seems I don't know the correct syntax.

Dim TxtValue As String
TxtValue = "Default Value"
Me.TxtBox.DefaultValue = TxtValue

The result of the code above is "#Name?" in the text box, not the desired "Default Value" string.
Please help.
 
You need more quotes round the string:

Me.TxtBox.DefaultValue = """Test"""
 
Yes, I realize that (for whatever reason) when you set the DefaultValue to a string you need 3 sets of quotes.
But what I want to do is set the DefaultValue to a variable that contains a string.
I've noted that, as per the suggestion in Help, if you try to set
Me.TxtBox.DefaultValue =Now()
the text box value is "#Name?"
However, if you set
Me.TxtBox.DefaultValue = "Now()"
the text box value is "8/25/2003 11:54:40 AM"
That implies that the .DefaultValue can only handle """string""" -type values OR values returned from a function call. However, I tried making a simple Function that returns the string that is passed to it, and that doesn't work.
Any ideas?
 
OK, nevermind.
This was one of those occasions I couldn't see the forest through the trees.
If anyone was paying attention and wants to know, don't use .DefaultValue when you want to set the entry of an unbound text box to a string variable.
Just set it like this:
Me.TxtBox = strVariable
Instead of like this:
Me.TxtBox.DefaultValue = strVariable
 
Hi,

Use this:
Me.TxtBox.DefaultValue = """ & strVariable & """
 
Ah. Thanks.
...I don't suppose you know how to write an update query, do you?
 
Stored queries run quicker than VBA SQL queries so unless the query is dynamically built(the update fields change each time), then you should build the query in the QBE grid and then run the query using:

Docmd.OpenQuery "QueryName"

To prevent update warnings use:

Docmd.SetWarnings False
Docmd.OpenQuery "QueryName"
Docmd.SetWarnings True

Note: Always reset the warnings to true after running the query to ensure you are notified of other alerts.

If you REALLY need to use VBA SQL then use Docmd.RunSQL "SQL Here" as in:

DoCmd.RunSQL "UPDATE Employees " & _
"SET Employees.Title = 'Regional Sales Manager' " & _
"WHERE Employees.Title = 'Sales Manager';"
 
True, I was referring to a topic in that other thread, but thanks for the suggestion anyway.
 

Users who are viewing this thread

Back
Top Bottom