2
votes

I'm trying to run the following on a normal text field in Notes, but it craps out. I'm wondering if maybe GetSelectedText won't work on plain text fields, though Help doesn't seem to indicate any such restrictions.

I want to get the text that the user selects in a field, and clear it. (Later on I'm going to replace it with the selected text that I've gone and done stuff to.)

Sub Click(Source As Button)

Dim wrksp As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As notesdocument
Dim seltext As String
Dim test As String
Dim BeginTag As String
Dim EndTag As String
Dim session As New NotesSession
Dim flag As Variant
Dim fieldName As String
fieldName = "Text"

Set uidoc = wrksp.CurrentDocument
Set doc=uidoc.document
On Error Goto nowtselected

seltext = uidoc.GetSelectedText(fieldname)
Msgbox seltext [Note: seltext comes back blank)
Call Session.SetEnvironmentVar( "EnvSelectedText", seltext )
Msgbox "got here1 fine"

Call uidoc.Clear
[Note: craps out completely upon attempting the above operation]
2

2 Answers

4
votes

I guess you put your code into a button on form. This doesn't work. When you click the button this button gets the focus and your field looses focus and selection at the same time. So, your code doesn't find anything selected in field.

Create an action button (menu Create/Action/Action.../Button) instead. Actions have the advantage not to change focus and selection on form. Your code itself is fine. You only need to transfer it to an action.

0
votes

Knut, when I transferred it to an Action Button the same problem occurred, and in fact I hadn't mentioned that it had been first in an action button, I was trying it in a regular on-page button out of sort of desperation.

But you made me think, I went, hmm, so clearly Knut thinks it should work back in an Action button (and the reasoning about the on-page button stealing the focus made total sense), so why didn't it work in an Action button, what is different and then I went, "aha!", (and the following is something I did not mention as I did not think it was relevant...)

The text field was set to be "Native OS Style" as opposed to the usual "Notes Style" (just to make the form prettier.) I switched it back to "Notes Style" and bingo my action button started working right away again. The script used did not like the field set as "Native OS Style."

But thanks Knut, you gave me some important information to help filter out other things! This field-type issue, which I always assumed was merely decorative, is definitely a new one on me!