Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Microsoft Jet Database error on form close

Status
Not open for further replies.

markronz

IS-IT--Management
Mar 20, 2007
93
US
Hello everyone-
I have a form that has multiple fields, each of which are bound to a column on a table. Four of the fields are required fields, and cannot be left blank. I am coming across an issue on the form when people fill in some required fields, but not all, then they try to navigate either to a different record, or else try to close the form.

When they do either of these things when the required fields are blank, it gives this error message:
"The Microsoft Jet database engine cannot find a record in the table 'tblAsset' with the key matching field(s) 'AsetID'.

If they close the form or move to a different record (via the record navigation buttons) and the four required fields ARE filled in, it save the record and then moves or closes.

So I need to find a way to catch the close of the form, or the move to the next record before they actually happen. That way I can check those four fields and prompt the user and cancel the action, instead of getting the error.

Does anyone know what sub procedure gets called in these two instances? Record navigation, and form close.

I've played with Form_Close and Form_Unload in an attempt to fix the closing the form part, but these are not right. The error pops up before those events even get fired.

Any suggestions? Thanks!
 
Use the Before updata event procedure of the form.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Bah! Of course! Sorry for the complex question with the simple answer. Thanks so much for the help!
 
Shoot, posted too soon. The BeforeUpdate event does get called before each the form close, and also the next record push. So it does work in this aspect.

For both, I set Cancel = True

On the record navigation, this takes care of my problem.

However, when the user clicks on the close button on the form, the before update event is called and I handle it, but then I get this message.

"You can't save the record at this time.
myDB may have encountered an error while trying to save a record. If you close this object now, the data changes you made will be lost. Do you want to close the database object anyway?"

I actually want to create my own custom message, and I've done so in the BeforeUpdate procedure. The problem is that when you close the form both message boxes pop up. My custom one first, and the above one second.

How do I get rid of that second error above?

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top