Error 5 in VB - Very Rare ... ???

I have a VB app I have loaded on at least 100 XP workstations.  It works without error probably 99.5% of the time.  It's a pretty simple message utility that uses an Oracle database.  It is a heavily used application (7x24) that stays active throughout each person's eight-hour shift.  About twice a month on assorted workstations, one or two users of this app will get an "Error 5 - Invalid Procedure Call or Argument" pop up.  It's not simultaneous; there doesn't seem to be any pattern.  They exit the app and restart, and all is well.  I have inserted an error handler to isolate the error, and it reports that the error occurs in "Housecleaning", a small section of code that handles some rather unspectacular tasks...

===================================================================

'Set Detail Error Message
    DetailError = "Housecleaning"

'Reset the display of both the groups and the people back to the top of the list, call
'WipeMessage to clear the entry box, set the Reciept Check to False, set Send to History
'to True, and set focus back to the entry box

    lstAllUserNames.TopIndex = 0
    lstAllGroups.TopIndex = 0
    chkReciept.Value = False
    chkHistory.Value = 1
    Call WipeMessage

'Re-enable the timer

    tmrSendMsg.Enabled = True

    Exit Sub

==================================================================

(This is the "Wipe Message" code which is called above):

Function WipeMessage()
   
    MousePointer = vbHourglass
   
   If ClearMsgAfterSend.Checked = True Then
      Text_Message.Text = vbNullString
   End If
   
    Text_Message.SetFocus
    MousePointer = vbNormal
   
End Function

==================================================================

I cannot find any reason for an Error 5 message.  Do you see anything that could trigger an error?



UPRRDevelopersAsked:
Who is Participating?
 
AjithJoseCommented:
If SetFocus method fails it will raise error 5: invalid procedure call

Just add a check, I think this will solve the problem

If Text_Message.Visible Then Text_Message.SetFocus

0
 
Erick37Commented:
Text_Message.SetFocus << will raise error 5 if it is not enabled.
0
 
Erick37Commented:
Also (unrelated) the Mousepointer should be set to vbDefault.  vbNormal is used for windowstates.  I think they are both 0 however.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
UPRRDevelopersAuthor Commented:
Thanks for the quick responses.  I read here about how setting focus to a disabled entity could cause that error.  The Text_Message box is set to enabled at startup, and I never, throughout the entire code, ever set it to enabled = False.
0
 
Erick37Commented:
Could the error be bubbling up from tmrSendMsg_Timer() ?
0
 
AjithJoseCommented:
Always add:

Text_Message.Visible=True

before

Text_Message.SetFocus




I think this is very unnessary error. We never need to know the result of a SetFoucs method.

~Ajith
0
 
UPRRDevelopersAuthor Commented:
Hmmmmm  ...   It is possible that I could have some weird loop in the code that causes a problem if a person has a certain screen condition when the timer goes off.  I'll have to check that out.
0
 
AjithJoseCommented:
Simply  add

On Error Resume Next before the setfocus call

Remember control will inherit the visible property from its container.

~Ajith
0
 
UPRRDevelopersAuthor Commented:
Ajith, I can see why it's a good idea to set the Visible setting to True before doing a SetFocus, and I'll do that in the future.  I just searched the code, and at startup, the box is set Visible = True, and it is never set either way for the rest of the entire app.  

I guess what really bothers me is, this app is used to send messages to other people in our office hundreds of times a day, and thousands of times per month.  If this was something like a disabled or invisible box setting, I would think it would be happening much more.  I know 20-30 errors out of 10,000 is very low, but as a developer, it is driving me nutz!  Thanks for the help so far.
0
 
UPRRDevelopersAuthor Commented:
Several good suggestions here.  I'll split the points and increase them overall because you guys were so quick and informative.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.