Window Close Button

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I just can remember....How do you get rid of the windows close button on a
form? "X" I want to force the user to use my exit button so that I can check
some fields.
 
You can set the Close Button property to No in the properties dialog for the
form. This isn't necessary. You can still force the checking of the field
when the user uses the Close button.

You use the form's Unload event to do your validation because it can be
canceled and the form will not close until it passes your validation:

Private Sub Form_Unload(Cancel As Integer)

If Not validated Then
MsgBox "Validation Failed"
Cancel = True
End If

End Sub

This is only an example. You would replace "Not validated" with the code to
validate your fields. If this code exists in another procedure in your code,
you can call that procedure to do the validation. For example, let's say
your validation is in the Before Update event of the form. Move the
validation code out of the event into a function that will return either True
or False. Then call that function from both events.
 
Perfect!!! Thank you Thank you Thank you!!!!

Klatuu said:
You can set the Close Button property to No in the properties dialog for the
form. This isn't necessary. You can still force the checking of the field
when the user uses the Close button.

You use the form's Unload event to do your validation because it can be
canceled and the form will not close until it passes your validation:

Private Sub Form_Unload(Cancel As Integer)

If Not validated Then
MsgBox "Validation Failed"
Cancel = True
End If

End Sub

This is only an example. You would replace "Not validated" with the code to
validate your fields. If this code exists in another procedure in your code,
you can call that procedure to do the validation. For example, let's say
your validation is in the Before Update event of the form. Move the
validation code out of the event into a function that will return either True
or False. Then call that function from both events.
 
Back
Top