简体   繁体   中英

Subform validation (datasheet view)

I have a subform where the user can create rows. A new row is created by clicking a button on the main form, after which the user can set the other values. Two fields are required, and the user must not be allowed to leave them empty, even by closing the form. Instead, a MessageBox should alert the user and he should stay on the offending row, allowing him to set the required values.

This must work even if the user has not made any change to the fields.

I'm trying different events with message boxes to see if any of them fire, but none of them fire when I try to leave the fields empty, for example by changing row or closing the main form. I'm looking for some equivalent to "OnBlur" in Javascript.

I've tried BeforeUpdate and On Dirty, but both of them require a change. I've solved the one for when closing the form, using On Unload with the Cancel parameter.

If I understood it correctly you are trying to validate user's entry before inserting a new row. Did you try the event 'Before Insert' of the subform? Use Cancel = -1 to disallow inserting. That should work even if the user tries to close the main form.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM