• stop the execution of a function (Access 2000)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » stop the execution of a function (Access 2000)

    Author
    Topic
    #382833

    I want to build a global function with the aim not to proceed further if the user had not
    chosen a selection fron the Option Box Office.
    The function is the following :
    Public Function MyFilter()
    If IsNull(Forms![FBenchmark]!Office) Then
    DoCmd.Beep
    MsgBox ” Please select Office first ! ”
    Exit Function
    End If
    End Function

    If there is no selection, then the message appears indeed
    but after that i receive different kinds of errors since after my global function i have different commands
    as opening a ofrm, report and so on.I could avoid that error by placing the further commands in the Else
    condition.But i do not want that, i want to build a fully independent function MyFilter to be used in a lot of cases and this function must not be influenced by the further commands in the OnClick events of the form. For example, i want to write the following:

    Call MyFilter
    DoCmd OpenForm ” Classes”
    etc
    etc

    Is that possible ?

    .

    Viewing 2 reply threads
    Author
    Replies
    • #650393

      Have your function return a value that indicates success/failure:

      Public Function MyFilter() As Boolean
      If IsNull(Forms![FBenchmark]!Office) Then
      DoCmd.Beep
      MsgBox ” Please select Office first ! ”
      MyFilter = False ‘ just to be explicit
      Else
      MyFilter = True
      End If
      End Function

      and call it as follows:

      If MyFilter = True Then
      DoCmd OpenForm ” Classes”

      End If

    • #650395

      If you want this function to be used in more than one situation you will need to pass values to the function when calling it. This means you will need to have one or more arguments in the function whose values you can test and then perform appropriate actions. For example instead of this:

      Public Function MyFilter()
      If IsNull(Forms![FBenchmark]!Office) Then
      DoCmd.Beep
      MsgBox ” Please select Office first ! ”
      Exit Function
      End If
      End Function

      It would look something like this:

      Public Function MyFilter(intOption as Integer)
      If IsNull(intOption) Then
      DoCmd.Beep
      MsgBox ” Please select Office first ! ”
      Exit Function
      End If
      End Function

      Not sure what all you are trying to accomplish – more details might be helpful.

    • #650496

      Simple, after you beep and alert the user. Open the form that let’s them select the ‘Office’, in Dialog mode. (Dialog mode will stop your calling code from running, until the dialog form/window is either closed, or hidden).

    Viewing 2 reply threads
    Reply To: stop the execution of a function (Access 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: