Set node value on View switch

J

Jeffshex

I know you can do code in the OnSwitchView event.
I'm trying to set 3 fields back to blank.
Is this done differently if I am using VBScript?

Thanks,
Jeff
 
S

Scott L. Heim [MSFT]

Hi Jeff,

Here is some sample VBScript code to set 3 fields to an empty string:

Sub XDocument_OnSwitchView(eventObj)
Dim objField1
Dim objField2
Dim objField3

If XDocument.View.Name = "vwTest" Then
Set objField1 = XDocument.DOM.selectSingleNode("//my:myFields/my:field1")
Set objField2 = XDocument.DOM.selectSingleNode("//my:myFields/my:field2")
Set objField3 = XDocument.DOM.selectSingleNode("//my:myFields/my:field3")

objField1.text = ""
objField2.text = ""
objField3.text = ""
End If
End Sub

I hope this helps!

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jeffshex

Here's the weird thing about it.
Let's say we are in form view 1 and switch to view 2 (which is used to look
up some things.)
If you don't set those few fields back to null and switch to view 1 and try
to lookup something again, nothing is returned until those fields are cleared
out.

Does that make sense?
I guess I need the the code to set values to null on exit of view 2.

Hopefully that is understandable.
 
S

Scott L. Heim [MSFT]

Hi Jeff,

So does the code I previously provided resolve it for you?

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jeffshex

Not 100% sure. It gets an "expected object" error and then points to the
line objFieldName.text = "" (I don't know why it doesn't like that line)
Anyways, it seems to run that code only when I switch from view 1 to view 2.
When I jump from view 2 back to view 1, those 3 fields don't clear out and
it causes view 1 to not work until you go back and clear em out.

Hope that explains it better.
Jeff
 
S

Scott L. Heim [MSFT]

Hi Jeff,

So a couple of things:

- If you look at the code, the reason it only works for one view is because
of the view "test" I incorporated. If you want to execute the code
regardless of the view, then simply remove the test.

- If you are getting an "object expected" error then typically this means
the XPath to your control is not correct.

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jeffshex

Scott,

I couldn't figure it out...so I just did it the poor man's way.
I put a button under those 3 fields that says "Switch to Main View"
Under that I have rules to set the value of those fields to ""
along with a switch views.
Pretty easy...yet it works.

-Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top