Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2014
    Posts
    22
    Provided Answers: 1

    Question Answered: 2 "actions" with 1 Event Procedure

    I have an "OnClick" Event Button on a Main Form/Switchboard which closes the database. I would like to have a msgbox asking if I really want to close the db. If yes, it closes. If No or Cancel, the msgbox goes away and the Main Form/Switchboard returns. Can I do this? Sorry I'm new to VB for Access programming. If this is NOT the correct area to post this question, please let me know.

  2. Best Answer
    Posted by bscottj48

    "That worked, Thanks."


  3. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    yes, but its down to how the code you have put in the event handle is written


    ...what code are you running at present
    I'd rather be riding on the Tiger 800 or the Norton

  4. #3
    Join Date
    Nov 2014
    Posts
    22
    Provided Answers: 1

    Code

    Currently it is a macro, but I would rather have it in VB for Access code.

  5. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so you have a command button

    in that command button's on click event

    use the msgbox method
    use the quit method
    you will need to decide what you want to do about any changes pending in the application. this is controlled by the AcQuckOption

    Code:
    'so the user wants to quit
    'are we certain or are they just jerking our chain?
    if msgbox("Close Application",vbyesno + vbquestion,"Mesage box title here") = vbyes then
      'so the user wants to quit
      me.quit(acQuickSaveNone) 'note make certain you choose the right AcQuitOption here
    'else
       'ok so they were jerking our chain, do nothing
    endif
    you coudl modify that dialog so that it offers the user the option of
    closing and saving pending changes
    closes without saving pending changes
    or don't close


    you'd do that by adding, say, a cancel button to the dialog box (replace vbyesno with vbyesnocancel)
    change the question to, say, "Do you want to quit and save changes"

    then test the respone from the message box
    if its vbyes then quite saving changes
    if its no then quit without saving changes
    if its cancel do nothing

    you might want to think about what your question should be and set the default button accordingly. theres' a whole ratft of settings for the message box identified here

    in the code above Ive tested the message box directly. if there are more than two options then you'd be better off assigning the value of the message box to a variable , then test that variable and take appropriate action
    if
    Last edited by healdem; 11-21-14 at 11:37.
    I'd rather be riding on the Tiger 800 or the Norton

  6. #5
    Join Date
    Nov 2014
    Posts
    22
    Provided Answers: 1

    Perfect thanks

    That worked, Thanks.

Tags for this Thread

Posting Permissions

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