Results 1 to 6 of 6
  1. #1
    RLehrbass is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2015
    Posts
    102

    What is the correct code command to keep a form open after selecting close control box button?

    Ok, I am at my Login Screen, I want it to return to the Login Screen if you select "NO" and Close the DB if "YES"

    Here is my current code:

    Private Sub Form_Close()

    If MsgBox("Would you like to EXIT the Database?", vbYesNo, "Quiting Database") = vbYes Then
    Application.Quit

    Else


    ???

    End If

    End Sub

  2. #2
    DrGUI is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Aug 2015
    Location
    Parts Unknown
    Posts
    23
    Try this:

    Private Sub Form_Close()

    If MsgBox("Would you like to EXIT the Database?", vbYesNo, "Quiting Database") = vbYes Then
    Application.Quit
    End If

    End Sub

    You will want to put this code in the Click event of the button not the Close event.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I suspect you're looking for

    Cancel = True

    but I don't think the close event can be cancelled. Try the unload event.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by pbaldy View Post
    ...
    but I don't think the close event can be cancelled. Try the unload event.
    That is what I am thinking.

  5. #5
    RLehrbass is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2015
    Posts
    102
    It needed to be in the event unload not the event cancel.

    Private Sub Form_Unload(Cancel As Integer)

    If MsgBox("Would you like to EXIT the Database?", vbYesNo, "Quiting Database") = vbYes Then
    Application.Quit

    Else
    Cancel = True

    End If
    End Sub

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I wish I'd have thought of that.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 2
    Last Post: 05-19-2015, 06:56 AM
  2. code to open table from Command Button
    By DMJ in forum Database Design
    Replies: 1
    Last Post: 02-20-2014, 12:33 PM
  3. Replies: 3
    Last Post: 07-11-2013, 11:52 AM
  4. Replies: 2
    Last Post: 05-11-2012, 11:52 AM
  5. Replies: 1
    Last Post: 05-03-2012, 02:25 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