Run Time Error 5 Invalid Procedure Call or argument

Posted on 2006-06-09
Last Modified: 2010-04-30
I have reviewed many questions and answers on this subject.  
I have no problem with the code when running from VB, only from the Exe.  
I have put messages at the Beginning and Ending of the Got Focus Routine of the TextBox that appears to be causing the problem, as well as at the Beginning and every few pieces of code in the Lost Focus Routine.  Running from within VB, I know that the code enters the Got Focus, User does not enter any data into the text box, just tabs off of it, Lost Focus is entered, BUT the Run Time Error 5 message is given after the message at the end of the Got Focus and before the message at the beginning of the Lost Focus.  

I have turned off all on error statements in the code and put in selected ones in these 2 routines.
This is a small portion of the code for the field that I get the error on when I leave it.
Private Sub txtSect_GotFocus()
'Color processing on focus
If ierror = 1 Then
    ierror = 0
    Exit Sub
End If
On Error GoTo Err1
ErrNum = 1
MsgBox "starting gotfocus on sect"

txtSect.BackColor = QBColor(1)
txtSect.ForeColor = QBColor(15)
If MySection > "" Or Hold_CourseId > "" Then
    ErrNum = 4
    txtSect.Text = MySection
    ErrNum = 5
    txtSect.Text = ""
End If
MsgBox "leaving section gotfocus"
ErrNum = 6
Exit Sub

MsgBox "error in sect gotfocus" + Str(ErrNum)
End Sub
Private Sub txtSect_LostFocus()
'Validate section number
<-----------------   Get Run time Error 5 before this message displays
MsgBox "about to start lost focus and check ierror"
On Error GoTo Err1
ErrNum = 10
If ierror = 1 Then
    ierror = 0
    Exit Sub
End If
If iclear = 1 Then
    iclear = 0
    Exit Sub
End If
MsgBox "checking isearch"
'   if isearch is set, rgcatlst has been called
ErrNum = 11
If isearch = 1 Then Exit Sub

MsgBox "txtsect lost focus, check for course id and section change"
ErrNum = 12
If Section = Trim(txtSect.Text) And txtCrsId > "" Then
    txtSect.BackColor = QBColor(15)
    txtSect.ForeColor = QBColor(0)
MsgBox "set colors on section, exiting Lost focus"
ErrNum = 13
    Exit Sub
End If

ErrNum = 14
Section = Trim(txtSect.Text)
ErrNum = 15

Exit Sub

MsgBox "error in sect gotfocus" + Str(ErrNum)
End Sub

Question by:LJPeterson
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 16900457
it seems that you never used that Restart: lable. Remove that entire lable or comment it then try again. It may solve the problem.

Author Comment

ID: 16905177
I did not included ALL of the code in the section.  There is code later that refers back to the Restart area.  I put messages in to make see if it is getting to that area, but it is not.  
When I run from the Exe, I get the 'leaving Section gotfocus' message and the cursor is on the field.  When I tab off without entering any info, I get the Run Time Error, clicking OK, I then get the 'About to start lost focus' message, clicking OK, the code then is unloaded.

Author Comment

ID: 17116233
I solved the problem myself. I had a SetFocus on another field in the form that did not have On Error code preceding it.  By stepping through the code, the processing did not go to the next field.  By putting more messages into the code for the next field in the Tab Order, I found that it went to the Got Focus and Lost Focus on that field before it went back to the Lost focus on the earlier field.  

Accepted Solution

Netminder earned 0 total points
ID: 17157173
Closed, 500 points refunded.
Site Admin

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Macro: print each sheet to pdf using ExportAsFixedFormat 11 71
using web browser with BING 40 150
Spell Check in VB6 13 148
Assign a value in Excel V-Basic 3 38
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

751 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