Apply test before allowing form to close

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

Guest

Hello All;

I would like to stop a user from closing a form if they have not filled in
certain fields under certain circumstances.

How can I stop the form from closing if my test parameters are not met?

Thanks in Advance for your help.

Bob
 
On the unload event of the form you can check if all the fields are filled ,
if not then give a message box, and the write cancel = true

If isnull(me.field1) then
msgbox "MyMessage"
cancel = true
end if
The other place you can put the code is in the before update event of the
form, but it will access this code only if one or more of the fields in the
form had been changed.
 
Thank you for your suggestion. After trying that I get a message that I can't
save the record at this time. Is that normal?

Thanks for your help

Bob
 
Hello All;

I would like to stop a user from closing a form if they have not filled in
certain fields under certain circumstances.

How can I stop the form from closing if my test parameters are not met?

Thanks in Advance for your help.

Use the Form's BeforeUpdate event: air code -

Private Sub Form_BeforeUpdate(Cancel as Integer)
Dim iAns As Integer
If IsNull(Me!requiredfield) Then <<< may need some nested If
statements if you have multiple conditions

<if the record is incomplete>

iAns = MsgBox("Please fill in X or press Cancel to erase", vbOKCancel)
Cancel = True ' stop the record from being saved
If iAns = vbCancel Then
Me.Undo ' erase all data on the form
End If

<end the outer if>

John W. Vinson[MVP]
 
I did get it sometimes.
Mybe there is a better way to get rid of it, but I put a close button on
the form, to check the fields, if all the fields are full I give the command
to close the form. if not I gave a message and exit the sub without closing
the form. give you more control.

also you have to remove the close form button in the top of the form.
set the CloseButton Property to no

sorry I dont have an answer for that error message
 
Back
Top