Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Sep 2002
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts

    stop the execution of a function (Access 2000)

    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 ?


    .

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: stop the execution of a function (Access 2000)

    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

  3. #3
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    NYC,USA,Earth
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: stop the execution of a function (Access 2000)

    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.

  4. #4
    4 Star Lounger
    Join Date
    Aug 2002
    Location
    Dallas, Texas, USA
    Posts
    594
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: stop the execution of a function (Access 2000)

    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).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •