Results 1 to 7 of 7
  1. #1
    4 Star Lounger
    Join Date
    Feb 2002
    Posts
    537
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Stop further lines of code (Access 2000)

    Is there any way to stop further execution of a click event?
    I have a function that gives a message if a control is visible Public Function NotDeleted()
    If Forms![Frm1]![Status].Visible = True Then
    DoCmd.Beep
    MsgBox " olala ! "
    DoCmd.CancelEvent
    End If


    However, if i have a click event with the function and another code, say Application.Quit acPrompt, then the next code is naturally executed.

    For example :
    in the OnClick event :
    NotDeleted
    Application.Quit acPrompt
    End Sub

    And my question is, can the NotDeleted function prevent the execution of the next code, i.e. Application.Quit acPrompt ?
    Does Access allow to stop the execution of a further line of code ? If it is possible i might use the NotDeleted function in many OnClick
    events with subsequent other lines of code

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Stop further lines of code (Access 2000)

    How familiar are you with VBA programming? I can't tell from what you posted what you're trying to accomplish with the CancelEvent. What event are you trying to cancel? If you are working in a form, the Unload event of the form allows for cancelling the event and keeping the form open. You simply have to use the correct event to get the result you want. If you are calling the function, have it return a value (which is what functions are for) and in the routine that calls the function branch your code conditionally.


    So in your OnClick event, you would do something like this:

    If NotDeleted() = True Then
    ' code to do whatever should be done if the control is visible
    Else
    Application.Quit acPrompt
    End If
    Charlotte

  3. #3
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Stop further lines of code (Access 2000)

    Alternatively, you could use the 'end' command in the NotDeleted code. That will stop execution stone dead.

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Stop further lines of code (Access 2000)

    End is very dangerous in VBA code. It stops ALL code execution but leaves the process active. I've never run across any recommendations for its use in the standard "bibles" on Access and VBA.
    Charlotte

  5. #5
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Stop further lines of code (Access 2000)

    Charlotte, forgive my ignorance but what do you mean when you say that the End command 'leaves the process active'?

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Stop further lines of code (Access 2000)

    If you're talking about the End statement, which is often used in VB development, but is fairly rare in VBA, here's a quote from Help:
    <hr>Note The End statement stops code execution abruptly, without invoking the Unload, QueryUnload, or Terminate event, or any other Visual Basic code. Code you have placed in the Unload, QueryUnload, and Terminate events of forms and class modules is not executed. Objects created from class modules are destroyed, files opened using the Open statement are closed, and memory used by your program is freed. Object references held by other programs are invalidated.<hr>
    Using End to stop code execution is not only abrupt, but in some cases it can break the Access app to the point where you can't even exit from Access. Using End is like pulling out one card from a house of cards. Everything comes crashing down but Access is left open.
    Charlotte

  7. #7
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Stop further lines of code (Access 2000)

    Thanks. Charlotte, I didn't realise how dramatic that command was!

Posting Permissions

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