InDesign CS2 : Find and change first result

Hello,

I want to search a word in InDesign CS2 document and change character style of the first result only.
Everything works except the last line :

tell application “Adobe InDesign CS2”
set find preferences to nothing
set change preferences to nothing
set theStyle to character style “SearchResult” of document 1
set searchResults to search documents with find attributes {find text:p_word}
set foundResult to item 1 of searchResults
set applied character style of text foundResult to theStyle
end tell

Can anyone help me ?

Hi. You need to strike the word “text” from the 2nd to last line, as you are already referring to a text.

this works :

tell application “Adobe InDesign CS2”
set find preferences to nothing
set change preferences to nothing
set theStyle to character style “SearchResult” of document 1
set searchResults to search documents with find attributes {find text:p_word}
set foundResult to item 1 of searchResults
set properties of foundResult to {applied character style:theStyle}
end tell

thanks