check to see if record saved

G

Guest

I have a form to create a progress report card for students. Along with the
form controls to gather information to create a printed report, I also have a
command button to save the record to an underlying table.

Is there code or some way that I can check on form close as to whether or
not this command button' click event has been passed, and, if not, prompt the
user to save?

I know this doesn't sound like a very efficient way to save the data, but I
want teachers to have the option not to save when they cancel the form, but
don't know how to differenciate between close and cancel.

Thank you.
 
A

Allen Browne

If this is a bound form, when the user closes it, Access will fire
Form_BeforeUpdate, the record will be saved, and then it will fire
Form_Unload, and finally Form_Close.

Since the record is *already* saved before the Unload or Close event, these
are too late to cancel the save. The last chance you have to do that is the
form's BeforeUpdate event.

There are many, many things that can cause a record to save, such as closing
the form, moving to a new record, filtering the form, changing the sort
order, closing Access, pressing Shift+Enter, choosing Save Record from the
Records menu, and so on. If you really must prevent the user saving through
any other means than your button, then you must create a boolean level
variable in the General Declarations section of the form's module, set it to
True in the click event of your button, and cancel Form_BeforeUpdate if it
is not True, and reset it in Form_BeforeUpdate.

Horrid interface, but that's how it can be done.
 
G

Guest

If the form has been save its Me.Dirty property will = False

'Function to Ask a question and return a booleen result
Public Function ConfirmYN(strMessage As String) As Boolean
' Ask the user to confirm an action, returning True or False.

Dim bytChoice As Byte

bytChoice = MsgBox(strMessage, vbQuestion + vbYesNo)

If bytChoice = vbYes Then
ConfirmYN = True
Else
ConfirmYN = False
End If

End Function

On Form Close

If Me.Dirty Then
Dim blnOK As Boolean
blnOK = ConfirmYN("Are you sure you want to Delete this Contract ?" &
"This Action Cannot be Un-Done")
If blnOK Then 'User Chose OK
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
End If
Hope this helps
 

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