Selecttext fails

S

sam_puploh

I'm trying to put something into the windows clipboard from IP:

Devised following test-code:

Sub XDocument_OnLoad(eventObj)
Dim oTekst: Set oTekst =
XDocument.DOM.selectSingleNode("//my:myFields/my:txbCP")
on error resume next
oTekst.Text = "Hello, this was entered in this box at form - load :
" & Right(Now(), 8)

XDocument.View.selecttext(oTekst.missing.value)

XDocument.View.ExecuteAction ("copy") ' Programmatically put in
clipboard.

if err.number <> 0 then
msgbox err.Description
err.Clear
end if

Set oTekst = Nothing

End Sub

I get an error in the ... XDocument.View.selecttext(oTekst) line
- also tried to insert "missing.value" to no avail?

Errormessage: an object is obligatory (translated from Danish, maybe
another error in English). I've transcripted from JS that I don't know
very wll, but it looks ok to me though?

What am I doing wrong?
 
S

S.Y.M. Wong-A-Ton

Errormessage: an object is obligatory (translated from Danish, maybe
another error in English).

Nice translation from Danish! It was close enough. :)

If you are getting the error message "Object is required" it means that
oTekst is Nothing. You can test this with the following line of code:

XDocument.UI.Alert(oTekst Is Nothing)

If oTekst is Nothing, you need to revise the XPath to the node. Try
something like "//my:txbCP" or "/my:myFields/my:txbCP" instead of
"//my:myFields/my:txbCP".

I tried out your code and made a few corrections. This is what I got to work:

Dim oTekst
Set oTekst = XDocument.DOM.selectSingleNode("//my:field1")
on error resume next
oTekst.text = "Hello, this was entered in this box at form - load :" &
Right(Now(), 8)

XDocument.View.SelectText(oTekst)

XDocument.View.ExecuteAction("Copy")

if err.number <> 0 then
msgbox err.Description
err.Clear
end if

Set oTekst = Nothing
 
S

sam_puploh

Hello S. Y. M. Wong-A-Ton

Thanks for your help - I will try it tomorrow at work. Strange though
about that object! The assignment of the text to the object works
without problems, so the object seems to point to the right control?

Anyhow, perhaps the view property needs another xpath as you suggest.

I'll dig into it tomorrow - thanks again

Regards Sam

sam_puploh skrev:
 
S

sam_puploh

Hello again,

had the opportunity to try it at home...

Made a completely new IP-form. Chose the on-open event from the
programming menu.

copied your code into it, and I still get same error.

The oTekst object IS something! - because ... a msgbox oTekst is
nothing ...tells me "FALSE".

So this is a real mystery for me.

What is going on?

Reg.
Sam



sam_puploh skrev:
 
S

S.Y.M. Wong-A-Ton

I'm not sure why it doesn't work for you. What version of InfoPath do you
have installed? 2003 with SP2?
 
S

S.Y.M. Wong-A-Ton

Also, try putting the code in the event handler for a button or somthing
else, rather than the OnLoad event for the form, since the View might not be
fully loaded in the OnLoad event.
 
S

sam_puploh

Even more strange! I put the code into a cmd_buttonclick event.

New error:

(Again translated from Danish: ...The chosen bstrAction-value for the
call to View.ExecuteAction can not be used with the actual
selection...)

If I remove the ExcecuteAction line I get this error:

.... The specified pxnField-value for the call to View.SelectText is not
valid ...

BTW IP 2003 SP2! (But Danish version, which is known for several
translation related bugs!)

I'm really baffled about these error especially because it seems to
work in your IP?

Can you give me another hint?


S.Y.M. Wong-A-Ton skrev:
 
S

sam_puploh

Forget about latest post - It was due to a mismatch for the
node-element (Used your english Field instead of Felt.

When this was corrected I'm back to my missing object problem which
started this dialog :(






sam_puploh skrev:
 
S

sam_puploh

Problem solved - at last.

IP didn't like the assignment to the node object in same procedure.
When I moved the SelectText to another function (and corrected my xpath
to two back-slaches it worked.

Thanks for the inspiration - hope someone can use this for the same
purpose!

sam_puploh skrev:
 
Top