yes / no message box on exit

Webster01

Registered User.
Local time
Today, 20:03
Joined
Mar 25, 2002
Messages
15
I would like to have completed forms locked to edits however I need to have a method of preventing someone from accidentally closing a form before it is completed which would result in an incomplete, uneditable form. I would like to have a meesage box appear on closing one record and before opening a new record to state "Do you want to close the present record?" and require a "yes" response before moving on. Thanks for your advice.
 
In the Forms Before Update event use code similar to this:

If IsNull(Me![MyField]) Then
Msgbox "You must fill in MyField before proceeding."
Cancel = True
Me![MyField].SetFocus
End If

Use similar code for each field on the form or use code to loop through them...

This will not allow the user to exit the record until all your requieded fields contain data.
 
Thanks for the reply.

This form may have some fields intentionally left blank, which is okay. What if I want to just make sure that the form is not "closed" and therefore locked to edits accidentally. Is there some global code that will require a response before actually leaving the current record and going on to a new blank form?
 
Then use the Before Update event with just a message....

Dim Response As Integer

Response = MsgBox("Are you sure you want to close this form?", vbCritical + vbYesNo + vbDefaultButton1)

If Response = vbYes Then ' (Default)
DoCmd.RunCommand acCmdSaveRecord
Exit Sub
Else 'vbNo
Cancel = True
Me.SomeField.SetFocus
End If
 

Users who are viewing this thread

Back
Top Bottom