Results 1 to 6 of 6
  1. #1
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581

    Cancel Button

    I'm trying to give a warning before the user takes action. I put a message box giving an option to continue or to cancel. But that's as far as I know how to go. The cancel button does not do anything. How do I make the cancel button cancel any action? Here's the code:

    Private Sub Command37_Click()
    On Error GoTo Command37_Click_Err

    MsgBox "OK will vacate this spot, or press CANCEL", vbOKCancel

    VacatedDate = Date
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "qryJobPositionNumbersVacate", acViewNormal, acEdit
    DoCmd.SetWarnings True
    DoCmd.Close , ""


    Command37_Click_Exit:


    Exit Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    If user is to pick the options, then MSGBOX must return a value as a function:

    Code:
    vRet = MsgBox( "OK will vacate this spot, or press CANCEL", vbOKCancel,"Confirm")
    
    
    if vRet = vbOK then
       VacatedDate = Date
       DoCmd.SetWarnings False
       DoCmd.OpenQuery "qryJobPositionNumbersVacate", acViewNormal, acEdit
       DoCmd.SetWarnings True
    endif
    
    
    DoCmd.Close

  3. #3
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    I got an error saying vbret = is not defined

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    you have to define your variables. I thought is was a given.
    Dim vRet

  5. #5
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    I'm making the transition from macros to VBA. Still forgetting a lot. Trying though.

  6. #6
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Awesome. Works great. Thanks.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Message Box Cancel Button
    By keith701a in forum Modules
    Replies: 7
    Last Post: 04-16-2018, 07:17 PM
  2. Cancel button
    By sprtrmp in forum Programming
    Replies: 7
    Last Post: 10-29-2015, 11:50 AM
  3. InputBox Cancel Button
    By mmaule in forum Access
    Replies: 4
    Last Post: 05-22-2014, 05:56 AM
  4. Cancel Button not working
    By alexandervj in forum Access
    Replies: 16
    Last Post: 02-06-2014, 12:27 PM
  5. Parameter Value Cancel button
    By Darkladymelz in forum Queries
    Replies: 1
    Last Post: 03-14-2012, 04:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums