Subject: RE: “Attempt to execute nested form events” error when calling uidoc.SelectAll() in Entering or OnFocus
I believe I have found a way around this. I’m not sure how helpful it will be to those of you that had the problem 3 years ago, and you may have already discovered it, but since it’s not posted here and one other person just had the problem, I thought I’d add to the list here for others.
This seems to work from read mode to edit mode as well as going directly into edit mode on a new document.
First, the field you want to select data in cannot be the first field. For some reason, the Entering event of the first field is attempting to run twice. I watched in debug as this happened. Thus, the error message. If the field you want selected needs to be the first field, you are going to need to hide a field before it. I tried doing this without the field in front, and it still gave the error. Now, you can’t hide it through the normal hide/when or it won’t work either. Also, this field cannot be computed. It must be editable. You can “hide” it by unchecking the “Show field delimiters” on the Control tab and make the text color the same as the background. The text color may not need set as you will never have anything in the field (unless you’d like to treat it like a label and have the same text in it always). But, that’s up to whatever you want. In the onFocus event of this field, you put:
document.forms[0].fieldNameToMoveTo.focus();
In the onBlur event you can do the following if you’d like to also ensure no data gets into it:
value = "";
Or, if you are using it like a label, assign the value whatever you assigned the default. But, again, nothing should ever get in the field, so you don’t have to do this part.
Next, in the field you want the data selected in, you’ll want to add the following code in the Entering event:
Sub Entering(Source As Field)
Dim ws As NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set ws = New NotesUIWorkspace
Set uidoc = ws.CurrentDocument
Call uidoc.SelectAll()
End Sub
You will still want this code in the Entering event to ensure that the data is selected other times than the initial opening of the document in edit mode. It doesn’t appear to run the first time the document opens, so it’s good to have it in there. You will also want to give initial (default) focus to this field on the Field Info tab as well. This will help a new document open with any default text selected as well.
Next, to get everything to work, you can do one of two things.
First, you can put it in your Edit button by adding the following code:
Sub Click(Source As Button)
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set uidoc = workspace.CurrentDocument
uidoc.EditMode = True
Call uidoc.GotoField("fieldNameToMoveTo")
Call uidoc.SelectAll
End Sub
This should suffice for you, or you can also do this in the Postmodechange event of the form:
Sub Postmodechange(Source As Notesuidocument)
If Source.EditMode = True Then
Call Source.GotoField("fieldNameToMoveTo")
Call Source.SelectAll()
End If
End Sub
Both of these things worked for me. You can even have them in the same form.
If you’d just rather use Formula in an Edit button to open the document in edit mode you need the Postmodechange event code above for sure. Otherwise, the code in the Lotusscript Edit button should do.
I believe all this only needs done if it’s the first field on the form that you wish to have data selected. If it is not, I don’t believe there is a problem. And, any other field in the document would only need the code in the Entering event.
The environment I did this in is a Notes 7 server with a 6.5.3 client.
Hope that helps others looking into this.
Thanks,
Jim