Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

literal quote inside default value 2

Status
Not open for further replies.

postermmxvicom

Programmer
Jun 25, 2007
114
US
I am setting the default value to the current value like so:
Code:
Me.Size.DefaultValue = """" & Me.Size.Value & """"
Size is a text field which can contain a lot of different kinds of input. The problem is when someone enters something like:
4" x 6' round
I obviously get a #name? error in the control. How do I manipulate the string to replace the " after the 4 with a "" so that it works correctly as a default value?

One last thing: Sometimes I wonder; "Is that someone's signature? Or do they type that at the end of each post?
 
Replace should suit:

Me.Size.DefaultValue = """" & Replace(Me.Size.Value,"'","''") &
 
Thanks Remou!

I was looking for a string manipulation function like that, but missed it.

I did have to alter your code just a tad, though.

Code:
Me.Size.DefaultValue = """" & Replace(Me.Size.Value, "[red]""[/red]", "[red]""""[/red]") & """"

Course clear, you get a star!

One last thing: Sometimes I wonder; "Is that someone's signature? Or do they type that at the end of each post?
 
Another way:
Code:
Me!Size.DefaultValue = "'" & Replace(Me!Size.Value, "'", "''") & "'"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,

Is there any advantage that one way has over the other, or any practical differences?

One last thing: Sometimes I wonder; "Is that someone's signature? Or do they type that at the end of each post?
 
I personally prefer to use double quotes for VBA literal constants and single quotes for the DB.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,

Does this come in handy when designing/maintaining your database? Or is it only a preference?

One last thing: Sometimes I wonder; "Is that someone's signature? Or do they type that at the end of each post?
 
I think this make the code clearer.
Compare this:
[tt]Me.Size.DefaultValue = """" & Replace(Me.Size.Value, """", """""") & """"[/tt]
with this ...
[tt]Me!Size.DefaultValue = "'" & Replace(Me!Size.Value, "'", "''") & "'"[/tt]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I see your point. It is much more readable.

Course clear, you got a star!

One last thing: Sometimes I wonder; "Is that someone's signature? Or do they type that at the end of each post?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top