Solved

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

Posted on 2004-10-25
195 Views
Last Modified: 2010-05-02
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?



0
Question by:UPRRDevelopers
    10 Comments
     
    LVL 32

    Expert Comment

    by:Erick37
    Text_Message.SetFocus << will raise error 5 if it is not enabled.
    0
     
    LVL 32

    Assisted Solution

    by:Erick37
    Also (unrelated) the Mousepointer should be set to vbDefault.  vbNormal is used for windowstates.  I think they are both 0 however.
    0
     

    Author Comment

    by:UPRRDevelopers
    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
     
    LVL 32

    Assisted Solution

    by:Erick37
    Could the error be bubbling up from tmrSendMsg_Timer() ?
    0
     
    LVL 4

    Assisted Solution

    by:AjithJose
    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
     

    Author Comment

    by:UPRRDevelopers
    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
     
    LVL 4

    Assisted Solution

    by:AjithJose
    Simply  add

    On Error Resume Next before the setfocus call

    Remember control will inherit the visible property from its container.

    ~Ajith
    0
     

    Author Comment

    by:UPRRDevelopers
    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
     
    LVL 4

    Accepted Solution

    by:
    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
     

    Author Comment

    by:UPRRDevelopers
    Several good suggestions here.  I'll split the points and increase them overall because you guys were so quick and informative.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now