Solved

Run Time Error 5 Invalid Procedure Call or argument

Posted on 2006-06-09
5
288 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Closed, 500 points refunded.
Netminder
Site Admin
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

763 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

7 Experts available now in Live!

Get 1:1 Help Now