Solved

Error Message: Invalid Outside Procedure

Posted on 2003-11-08
8
628 Views
Last Modified: 2012-05-04
Using Access 2000. I am using the following two procedures. The first one is in the form's general declaration section, and the second one is in the Combo Box's Not In List property, which by the way has it's Limit To List property set to yes.

[First One]
Private Function IsLoaded(strName As String, _
 Optional lngType As AcObjectType = acForm) As Boolean
    IsLoaded = (SysCmd(acSysCmdGetObjectState, _
     lngType, strName) <> 0)
 End Function

[Second One]
Private Sub cboKeyCode_NotInList(NewData As String, Response As Integer)
    Dim mbrResponse As VbMsgBoxResult
    Dim strMsg As String
   
    strMsg = NewData & _
     " isn't an existing Key Code. " & _
     "Add a new Key Code?"
    mbrResponse = MsgBox(strMsg, _
     vbYes + vbQuestion, "Invalid Key Code")
    Select Case mbrResponse
        Case vbYes
            DoCmd.OpenForm "Key Code", _
                DataMode:=acFormAdd, _
                WindowMode:=acDialog, _
                OpenArgs:=NewData
               
                'Stop here and wait until the form goes away
                If IsLoaded("Key Code") Then
                    Response = acDataErrAdded
                    DoCmd.Close acForm, "Key Code"
                Else
                    Response = acDataErrContinue
                End If
        Case vbNo
            Response = acDataErrContinue
    End Select
End Sub

Here's the problem...When I attempt to enter a value into the Combo Box which is not in the list, I am getting the error message: Invalid Outside Procedure. What do I need to do to correct this procedure? Thanks in advance for your assistance.
0
Comment
Question by:CatDaddy2003
  • 4
  • 3
8 Comments
 
LVL 32

Expert Comment

by:jadedata
ID: 9707226
Hey CatDaddy2003!

  The procedures have no error trapping in them.  Insert error trap with a msgbox...

  Proc_Err:
    select case err
    case else
      msgbox "Error: " & err & " - " & Error$
      resume Proc_Exit
      resume
    end select

When the error occurs, activate the "resume" line (click on it and {CTRL}{F9})
Then {F8} will take you to the line that is causing the error..
 
regards
Jack
0
 

Author Comment

by:CatDaddy2003
ID: 9707308
OK, what I did was to add your procedure to the OnError propety of the form. This did not produce the anticipated results. Was I wrong? If so, where did I go wrong? Thanks in advance...
0
 
LVL 32

Expert Comment

by:jadedata
ID: 9707323
The section of code goes into each procedure you write.  It traps and reports error occuring in that procedure

  Example:

Private Function IsLoaded(strName As String, Optional lngType As AcObjectType = acForm) As Boolean

  on error goto IsLoaded_Err:

  IsLoaded = (SysCmd(acSysCmdGetObjectState, lngType, strName) <> 0)

Isloaded_Exit:
  on error resume next
  exit function

Isloaded__Err:
    select case err
    case else
      msgbox "Error in MODULENAME.Isloaded: " & err & " - " & Error$
      resume Isloaded__Exit
      resume
    end select

 End Function
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:CatDaddy2003
ID: 9707373
Ok, something I am still doing wrong. FYI, here are the revised procedures. Any ideas?

*****************************
Private Function IsLoaded(strName As String, _
 Optional lngType As AcObjectType = acForm) As Boolean
 
 On Error GoTo IsLoaded_Err:
 
 IsLoaded = (SysCmd(acSysCmdGetObjectState, lngType, strName) <> 0)
 
Isloaded_Exit:
  On Error Resume Next
  Exit Function

Isloaded__Err:
    Select Case Err
    Case Else
      MsgBox "Error in MODULENAME.Isloaded: " & Err & " - " & Error$
      Resume Isloaded__Exit
      Resume
    End Select

 End Function
 
    IsLoaded = (SysCmd(acSysCmdGetObjectState, _
     lngType, strName) <> 0)
 End Function

*******************************

Private Sub cboKeyCode_NotInList(NewData As String, Response As Integer)
    Dim mbrResponse As VbMsgBoxResult
   
    On Error GoTo cboKeyCode_Err:
   
    cboKeyCode = (SysCmd(acSysCmdGetObjectState, lngType, strName) <> 0)
   
KeyCode_Exit:
  On Error Resume Next
  Exit Function
   
KeyCode_Err:
    Select Case Err
    Case Else
      MsgBox "Error in MODULENAME.Isloaded: " & Err & " - " & Error$
      Resume KeyCode_Exit
      Resume
    End Select

 End Function
   
    Dim strMsg As String

    strMsg = NewData & _
     " isn't an existing Key Code. " & _
     "Add a new Key Code?"
    mbrResponse = MsgBox(strMsg, _
     vbYes + vbQuestion, "Invalid Key Code")
    Select Case mbrResponse
        Case vbYes
            DoCmd.OpenForm "Key Code", _
                DataMode:=acFormAdd, _
                WindowMode:=acDialog, _
                OpenArgs:=NewData
               
                'Stop here and wait until the form goes away
                If IsLoaded("Key Code") Then
                    Response = acDataErrAdded
                    DoCmd.Close acForm, "Key Code"
                Else
                    Response = acDataErrContinue
                End If
        Case vbNo
            Response = acDataErrContinue
    End Select
End Sub
0
 
LVL 32

Expert Comment

by:jadedata
ID: 9707392
Is there any particular reason you changed the order of the sections in the code

  Public Function FuncName()

    dims.....

    on error goto
   
    function code.....

    exit gate....

    error trap....

    End Function
0
 

Author Comment

by:CatDaddy2003
ID: 9707523
Nope just in a hurry and had to leave for a moment. I have revised the procedures as the following, with same results...????????

****************

Private Function IsLoaded(strName As String, _
 Optional lngType As AcObjectType = acForm) As Boolean
 
    On Error GoTo IsLoaded_Err:
   
    IsLoaded = (SysCmd(acSysCmdGetObjectState, _
     lngType, strName) <> 0)
     
IsLoaded_Exit:
        On Error Resume Next
        Exit Function
       
IsLoaded_Err:
    Select Case Err
    Case Else
        MsgBox "Error in MODULENAME.IsLoaded: " & Err & " - " & Error$
        Resume IsLoaded_Exit
        Resume
    End Select
 End Function

****************************

Private Sub cboKeyCode_NotInList(NewData As String, Response As Integer)

    Dim mbrResponse As VbMsgBoxResult
    Dim strMsg As String
   
    On Error GoTo cboKeyCode_Err:
   
   
    strMsg = NewData & _
     " isn't an existing Key Code. " & _
     "Add a new Key Code?"
    mbrResponse = MsgBox(strMsg, _
     vbYes + vbQuestion, "Invalid Key Code")
    Select Case mbrResponse
        Case vbYes
            DoCmd.OpenForm "Key Code", _
                DataMode:=acFormAdd, _
                WindowMode:=acDialog, _
                OpenArgs:=NewData
               
                'Stop here and wait until the form goes away
                If IsLoaded("Key Code") Then
                    Response = acDataErrAdded
                    DoCmd.Close acForm, "Key Code"
                Else
                    Response = acDataErrContinue
                End If
        Case vbNo
            Response = acDataErrContinue
    End Select
   
cboKeyCode_Exit:
    On Error Resume Next
    Exit Function
   
cboKeyCode_Err:
    Select Case Err
    Case Else
        MsgBox "Error in MODULENAME.cboKeyCode: " & Err & " - " & Error$
        Resume cboKeyCode_Exit
        Resume
    End Select
End Sub
0
 
LVL 9

Accepted Solution

by:
ornicar earned 500 total points
ID: 9707715
'invalid outside procedure' indicates when there is code somewhere not between Function...End Function or Sub...End Sub. Check perhaps in the 'Key Code" form, as the error raises when you enter sonething not in list.
0
 
LVL 32

Expert Comment

by:jadedata
ID: 9708739
Compile the project and the compiler should land you on the culprit line immediately.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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…
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…

785 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