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

x
?
Solved

Error Message: Invalid Outside Procedure

Posted on 2003-11-08
8
Medium Priority
?
655 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

926 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