Results 1 to 7 of 7
  1. #1
    Join Date
    May 2002
    Posts
    395

    Unanswered: disable the "close" option on the upper right corner of a form

    I would like to disable the "close" option on the upper right corner of a form so the user must use the CLOSE button. I know you can use the SendKeys statement but it doesn't work for me.

    Private Sub cmdClose_Click()
    On Error GoTo Err_cmdClose_Click

    SendKeys "{ESC}", 1

    DoCmd.Close


    Exit_cmdClose_Click:
    Exit Sub

    Err_cmdClose_Click:
    MsgBox Err.Description
    Resume Exit_cmdClose_Click

    End Sub

    Thanks!!

  2. #2
    Join Date
    Aug 2002
    Location
    Charlotte NC
    Posts
    665
    So you dont want the x in the upper right hand corner to work?
    you can disable that in the properties of the form, just set the close button property to no
    regards
    Jim

  3. #3
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820
    it you want the vb

    sub on_load()
    Me.CloseButton = False
    end sub
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

  4. #4
    Join Date
    Nov 2002
    Posts
    4
    Dim fOKToClose As Boolean

    Private Sub Exit_Database_Click()
    On Error GoTo Err_Exit_Database_Click

    ' If you click the Close button, set the variable
    ' so the Unload event will let you out.
    fOKToClose = True
    DoCmd.Close

    Exit_Exit_Database_Click:
    Exit Sub

    Err_Exit_Database_Click:
    MsgBox Err.Description
    Resume Exit_Exit_Database_Click

    End Sub

    Private Sub Form_Load()

    ' Set the trap, so no one can close the form without
    ' clicking the Close button.
    fOKToClose = False
    DoCmd.Maximize

    End Sub

    Private Sub Form_Unload(Cancel As Integer)

    Dim strMessage As String
    Dim intStyle As Integer
    Dim strTitle As String

    strMessage = "You are attempting to exit the database incorrectly." & _
    vbCrLf & "Please try again using the Exit Database button"
    intStyle = vbOKOnly + vbCritical
    strTitle = "Exit the database?"

    If fOKToClose = False Then
    MsgBox prompt:=strMessage, buttons:=intStyle, Title:=strTitle
    Cancel = Not fOKToClose
    Exit Sub
    Else
    DoCmd.Quit
    End If

    End Sub

  5. #5
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820
    why all the effort that involves when you can just turn of the close button?
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

  6. #6
    Join Date
    Nov 2002
    Posts
    4
    This eliminate all options such as file close

  7. #7
    Join Date
    May 2002
    Posts
    395

    disable to the close button on uppr rt side of the form

    Originally posted by m.timoney
    it you want the vb

    sub on_load()
    Me.CloseButton = False
    end sub
    I am still trying to disable the close button of the form and this is the error message I received:
    " You can't assign a value to this object"
    I placed the code in the on_load sub of the form.
    When I step through the code the current status of Me.CloseButton is True. Why couldn't I set it to false anyway?

Posting Permissions

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