BeforeUpdate Event

N

NH

I am trying to use the BeforeUpdate event to trap make
sure certain fields are filled in correctly before closing
a form. (Thanks to Allen Browne for the tip)

But I keep getting the message:

"You ca't save this record at this time. MsAccess may have
encountered an error while trying to save a record.
--snip--
Do you want to close the database object anyway?"

All I am doing is exiting the sub with Cancel = True..

How can I stop this message?

Thanks

NH
 
A

Allen Browne

The BeforeUpdate event of the form or that of a control?

This is a built-in message that is displayed if the user attempts to close
the form while the record is dirty, and you cancel Form_BeforeUpdate. The
message gives them the choice to close'n'lose'edits, or stay with the edit.
If that's what you are talking about, you can probably leave the message in
place and allow the user that choice, or not show the close button on the
form.
 
N

NH

Thanks for the response,

I have put it in the Form_BeforeUpdate..

To put it simply, when the 'x' button is pressed, if len
([myfield]&"") < 1 I just want it to cancel the whole
close process, and go back the form displaying a
simple "You must fill in My Field!" message box... rather
than display the generic message..

I'm sure I've done it before, I just can't remember which
events I trapped.
 
A

Allen Browne

Yes, this message is not well implemented.
Even if you cancel Form_BeforeUpdate and undo the form, it still fires.

You can use the form's Error event to trap it:

Private Sub Form_Error(DataErr As Integer, Response As Integer)
If DataErr = 2169 Then
Response = acDataErrContinue
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

NH said:
Thanks for the response,

I have put it in the Form_BeforeUpdate..

To put it simply, when the 'x' button is pressed, if len
([myfield]&"") < 1 I just want it to cancel the whole
close process, and go back the form displaying a
simple "You must fill in My Field!" message box... rather
than display the generic message..

I'm sure I've done it before, I just can't remember which
events I trapped.


-----Original Message-----
The BeforeUpdate event of the form or that of a control?

This is a built-in message that is displayed if the user attempts to close
the form while the record is dirty, and you cancel Form_BeforeUpdate. The
message gives them the choice to close'n'lose'edits, or stay with the edit.
If that's what you are talking about, you can probably leave the message in
place and allow the user that choice, or not show the close button on the
form.
 

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