how to restric user to close a form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • muddasirmunir
    Contributor
    • Jan 2007
    • 284

    how to restric user to close a form

    i am using vb6
    i want to restirct user to close a form if it has a blank field

    for e-g if user did not write name is the box and he tries to close
    the form by clicking on the croos button at top right it will be promte
    to write name

    i konw coding but i want to knowwhere we had to write this code
    at unload event of form or teminate or some other
  • lotus18
    Contributor
    • Nov 2007
    • 865

    #2
    Originally posted by muddasirmunir
    i am using vb6
    i want to restirct user to close a form if it has a blank field

    for e-g if user did not write name is the box and he tries to close
    the form by clicking on the croos button at top right it will be promte
    to write name

    i konw coding but i want to knowwhere we had to write this code
    at unload event of form or teminate or some other
    At the Unload event, check for the textbox. If it is empty then pop up a message and Cancel=1.

    Rey Sean
    Last edited by lotus18; May 25 '08, 12:05 PM. Reason: change amd to and

    Comment

    • devonknows
      New Member
      • Nov 2006
      • 137

      #3
      I think you'll be better off using the query unload method. (Form_QueryUnlo ad) as not only can you stop the code from unloading you can also check how it is being closed wether it is being forcably shutdown by windows, by task manager or by client.

      so summet like

      Code:
       
      Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
      	If Len(Text1.Text) < 1 Or Combo1.ListIndex = -1 Then
      		MsgBox "Please insert a value.", vbCritical, "Error"
      		Cancel = 1
      	End If
      End Sub
      Kind Regards
      Devon

      Comment

      Working...