Solved

Run Time Error 5 Invalid Procedure Call or argument

Posted on 2006-06-09
5
294 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
[X]
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
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Suggested Courses
Course of the Month4 days, 21 hours left to enroll

635 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