" - Quotes

S

SC

Hi All,

I'm trying to display a note in a text box. The line of code is simply:

txtNote.ControlSource = "=" & Chr(34) & ListNotes.SelectedItem. & Chr(34)

the problem is that anytime the note itself has a " in it, it causes an
error. Are there any creative ways around this?

Thanks,

Steve
 
D

Douglas J. Steele

Use the Replace function to change any instance of a double quote in the
text to two instances of a double quote.

txtNote.ControlSource = "=" & Chr(34) & Replace(ListNotes.SelectedItem,
Chr(34), Chr(34) & Chr(34)) & Chr(34)
 
D

Dirk Goldgar

In
SC said:
Hi All,

I'm trying to display a note in a text box. The line of code is
simply:

txtNote.ControlSource = "=" & Chr(34) & ListNotes.SelectedItem. &
Chr(34)

the problem is that anytime the note itself has a " in it, it causes
an error. Are there any creative ways around this?

Doug gave you an answer that solves the problem with the quotes, but I'm
curious: is there a reason you're setting the text box's controlsource
expression, binding the text box on the fly to a static expression,
rather than leaving the text box unbound and just setting its value to
the text of the note? E.g.,

txtNote = ListNotes.SelectedItem
 
S

SC

Thanks

Douglas J. Steele said:
Use the Replace function to change any instance of a double quote in the
text to two instances of a double quote.

txtNote.ControlSource = "=" & Chr(34) & Replace(ListNotes.SelectedItem,
Chr(34), Chr(34) & Chr(34)) & Chr(34)
 
Top