Solved

Run Time Error 5 Invalid Procedure Call or argument

Posted on 2006-06-09
5
290 Views
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
Else
    ErrNum = 5
    txtSect.Text = ""
End If
MsgBox "leaving section gotfocus"
ErrNum = 6
Exit Sub

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

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

Exit Sub

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

0
Comment
Question by:LJPeterson
  • 2
5 Comments
 
LVL 9

Expert Comment

by:pradapkumar
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.
0
 

Author Comment

by:LJPeterson
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.
0
 

Author Comment

by:LJPeterson
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.  
0
 
LVL 5

Accepted Solution

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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 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…

867 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

22 Experts available now in Live!

Get 1:1 Help Now