VBscript error for script on OnAfterChange Event

C

cmenconi

I am having an issue with a vbscript set to run as a Data Validation
script triggered by an OnAfterChange event.

The Error I get is An error occurred in the form's code. The number of
calls to the OnAfterChange event for a single update in the data
exceeded the maximum limit.

I have found a few articals on this error but all of them pointed to
jscript which I am unfamiliar with.

--Script------
Sub msoxd_my_txtServerName_OnAfterChange(eventObj)

' Write code here to restore the global state.

If eventObj.IsUndoRedo Then
' An undo or redo operation has occurred and the DOM is read-only.
Exit Sub
End If

' A field change has occurred and the DOM is writable. Write code here
to respond to the changes.
Dim objServerName
Set objServerName =
XDocument.DOM.selectSingleNode("//my:myFields/my:txtServerName")
objServerName.text = ucase(objServerName.text)
End Sub
--end script-----

Any help would be much apperciated... Thanks!
 
B

bratt

Since you are changing the object in a onafterchange event on it you
will fire the event yourself. you can setup a semaphore flag to only
execute the code once:

dim ModifyItem = false
Sub msoxd_my_txtServerName_OnAfterChange(eventObj)


' Write code here to restore the global state.


If eventObj.IsUndoRedo or ModifyItem Then
' An undo or redo operation has occurred and the DOM is read-only.
Exit Sub
End If

ModifyItem = true ' make sure this code is only executed once
' A field change has occurred and the DOM is writable. Write code here
to respond to the changes.
Dim objServerName
Set objServerName =
XDocument.DOM.selectSingleNode("//my:myFields/my:txtServerName")
objServerName.text = ucase(objServerName.text)
ModifyItem = false ' set it back to complete for next time
End Sub
 

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