Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Nov 2001
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can i stop further codes? (Access 2000)

    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

  2. #2
    2 Star Lounger
    Join Date
    Apr 2001
    Location
    Wellington, New Zealand
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can i stop further codes? (Access 2000)

    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.

  3. #3
    2 Star Lounger
    Join Date
    Apr 2001
    Location
    Wellington, New Zealand
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can i stop further codes? (Access 2000)

    Here is an example
    Attached Files Attached Files

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Can i stop further codes? (Access 2000)

    Hi,
    I would change your function slightly so that it returns a value - e.g.
    <pre>Private Function DisregardCity() As Boolean
    DisregardCity = False
    If Me![OptCity] <> 0 Then
    MsgBox "Please disregard size !!"
    DisregardCity = True
    End If
    End Function
    </pre>

    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.
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

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