Results 1 to 2 of 2
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Close Event (A2k Sr1)

    I need to set a condition with a form if a user tries to close a certain form.
    If the user tries to close the form and Status is "I" (Eye)
    Then the form fails to close and sets focus back.

    If the condition is any other than "I", the form can happily close and let the user proceed.



    Private Sub Form_Close()
    'This code to run if Status ="I"
    'And form to NOT close, but setfocus back to DummyEst Field
    '************************************************* ***********

    If Me.Status = "I" Then
    Dim intButSelected As Integer, intButType As Integer
    Dim strMsgPrompt As String, strMsgTitle As String
    strMsgPrompt = "This File Has been Invoiced But Not F'd. This Will Now Be Updated Automatically"
    strMsgTitle = "!!"
    intButType = vbOKOnly + vbDefaultButton1
    intButSelected = MsgBox(strMsgPrompt, intButType, strMsgTitle)
    If intButSelected = vbOKOnly Then
    Forms!frmdetails.SetFocus
    Forms!frmdetails!DummyEst.SetFocus
    Forms!frmdetails!Status = "F"
    End If
    End If

    'The following to run if status is anything other than "I"
    'And form to close as requested.
    '************************************************* *********
    Forms!mnuworkshopmanager.Visible = True
    Forms!mnuworkshopmanager.SetFocus
    Forms!mnuworkshopmanager!cmbWorkShop.SetFocus
    Forms!mnuworkshopmanager!cmbWorkShop.Dropdown
    Exit Sub
    End Sub


    Dave

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Close Event (A2k Sr1)

    The Close event of a form has no option to cancel it, but the Unload event does:

    Private Sub Form_Unload(Cancel As Integer)
    If Status = "I" Then
    ' Show message box, etc. here
    Cancel = True
    End If
    End Sub

Posting Permissions

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