Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / October 2006

Tip: Looking for answers? Try searching our database.

urgent : error handler in Infopath 2003 VBS

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Didier Maignan - Interprojet - 20 Oct 2006 17:44 GMT
Contrary to VBA, There is no "ON error goto" to handle error and prevend
users from seiign a call for ...debugging the form.

I see a lot of stuff on JS but nothing consistent on VBS. Can you propose a
VBS generic code to show a message box on error occuring with the
errordetailedDescription as an information message box  (and with no button
for debugging)

Thx a lot
S.Y.M. Wong-A-Ton - 21 Oct 2006 02:05 GMT
To get a misconception out of the way: The VBScript used in InfoPath is not a
"special kind" of VBScript. It is the normal VBScript used everywhere else
for scripting. Since VBA is a close cousin of Visual Basic (the programming
language), it supports many things that VB supports. VBScript is quite
limited compared to VB.

Having said that, you can use "On Error Resume Next" at the top of your code
and then test for Err.Number being unequal to zero after each line where you
suspect an error might occur. So do something like

Dim obj
On Error Resume Next
Set obj = CreateObject("Foo")
If Err.number <> 0 Then
 MsgBox "An error occurred"
End If

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

> Contrary to VBA, There is no "ON error goto" to handle error and prevend
> users from seiign a call for ...debugging the form.
[quoted text clipped - 5 lines]
>
> Thx a lot
Didier Maignan - Interprojet - 22 Oct 2006 22:40 GMT
Thx a lot SYM

This is very interesting. It works.  I tried to go further now. I explore
with very little success several solution to track the exact error so that
users are not trapped with a debugging error.
The fact is that VBS Infopath error events are apparently 2 : resume and
goto 0
Is it possible to build a module for error management with that ?

FYI My code makes call to XML and to SQL server as datasources, and also
writes onto Project Professional wich can also trigger error if the
application meets a problem.

for instance something like this :
If err.number<>0 then
message="Error N° "& Err.number & " of type " & Err.Source & " appeared : "
& chr(13) & Err.Description  & " Please contact your admin."
MyVar=msgbox(message ,48,"error was detected in your form" )

this one does not work properly.

Can you help with detailed error handling ?

> To get a misconception out of the way: The VBScript used in InfoPath is not a
> "special kind" of VBScript. It is the normal VBScript used everywhere else
[quoted text clipped - 25 lines]
> >
> > Thx a lot
S.Y.M. Wong-A-Ton - 23 Oct 2006 01:11 GMT
Why does it not work properly, Didier? Are you getting error messages? Other
than not having broken the message string properly, it worked fine for me.

You must let the concept of "modules" go when using VBScript. What you can
do is write a general function or subroutine that will display an error
message when an error occurs, and call this function/sub after each line in
your code where you think an error might occur. So add a function like this
to your code

Sub CheckForErrors
 Dim Message
 Dim Answer
 If Err.number <> 0 Then
   Message= "Error N° " & Err.number & " of type " & Err.Source & "
appeared: " & Chr(13) & Err.Description & " Please contact your admin."
   Answer = MsgBox(Message ,48,"error was detected in your form")
 End If
 Err.Clear
End Sub

Remember to use proper line continuation characters (&_) when constructing
the string for the "Message". Then you can call this sub after each line in
your code like this

Dim obj
On Error Resume Next
Set obj = CreateObject("Foo")
CheckForErrors

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

> Thx a lot SYM
>
[quoted text clipped - 48 lines]
> > >
> > > Thx a lot
Didier Maignan - Interprojet - 23 Oct 2006 12:18 GMT
Thx SYM

We tried that. Thansk la lot.
If there is an error (Foo or databse connection or whatelse ) this is OK
But in case of no error : there is an ... error on the line :
If Err.number <> 0 Then

so this procedure is not applicable for all cases , except if there IS an
error.
So this is not convenient.

Didier

> Why does it not work properly, Didier? Are you getting error messages? Other
> than not having broken the message string properly, it worked fine for me.
[quoted text clipped - 80 lines]
> > > >
> > > > Thx a lot
S.Y.M. Wong-A-Ton - 24 Oct 2006 07:01 GMT
Let me see if I understood you correctly. If you add "If Err.number <> 0
Then" etc. in your code and no error occurred, the line causes an error? If
so, what is the error message?

I tried it and it worked fine on my end. Try creating a new form (a clean
start) with a button that has only that line of code (including and End If of
course) in it and test it. The only error that I can imagine taking place is
that the "Err" object could be "Nothing", but according to me this object is
always defined.
---
S.Y.M. Wong-A-Ton

> Thx SYM
>
[quoted text clipped - 93 lines]
> > > > >
> > > > > Thx a lot
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.