• Can i stop further codes? (Access 2000)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Can i stop further codes? (Access 2000)

    Author
    Topic
    #368448

    I need to stop the execution of any codes or function whenever i use my global function DisregardCity.
    My task is the following.Sometimes the user must not use the option box DisregardCity and use the other 2 options.
    Therefore if the user uses the option group DisregardCity, he must receive the message “Please disregard the city” and
    must be returned to the initial position, preventing the execution of the codes. But i cannot stop the other codes from executing.
    I will give an exampple. I have the following picture.The user chooses from the option group City, then goes to the second option group
    to select a counry and then to another option group to select the month and opens a report.Then the message appears “Please disregard

    the size” and after entering the OK, the report is being opened.I do not want to open the report in this case, i want that the function

    DisregardCity stops any further code, clears any functions and retruns to the initial position.
    I have tried with DoCmd.Cancedl event, alos with closing and opening the form again, and also with Exit Function, but the report continues to be opened even though i have placed the function DisregardCity”
    May i receive some help in my problem”
    Here is my function:

    Private Function DisregardCity()
    If Me![OptCity] 0 Then
    MsgBox “Please disregard size !!”
    End If
    End Function

    Viewing 2 reply threads
    Author
    Replies
    • #577406

      The way that I would approach this is to use a global variant to indicate the state of whethere a use is allowed to continue or not. The in the open events of the report, use check the global variable and if the user is not allowed to proceed set CANCEL = true to prevent the report from opening.

      To use a global varianble, in a module outside of a proceedure (ie. at the top of the module) declare the variable using the Public statement.

    • #577407

      Here is an example

    • #577412

      Hi,
      I would change your function slightly so that it returns a value – e.g.

      Private Function DisregardCity() As Boolean
      DisregardCity = False
      If Me![OptCity]  0 Then
      MsgBox "Please disregard size !!"
      DisregardCity = True
      End If
      End Function
      

      This way, in your calling code, you can test for the return value and only execute the following code if DisregardCity returns False (i.e. If Not DisregardCity() Then…)
      Hope that helps.

    Viewing 2 reply threads
    Reply To: Can i stop further codes? (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: