Window Close Button

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.
 
G

Guest

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.
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top