Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Run Time Error 5 Invalid Procedure Call or argument

Posted on 2006-06-09
5
Medium Priority
?
299 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

916 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