See below:
Dan McClelland said:
Ahhhhh. So, if I understand this correctly, after
entering the first character in a new record, the
BeforeInsert event is triggered and a temporary record is
created which holds your data. When you do a Save Record,
the temporary record is updated and it goes into the table
as a "permanent" record? Why didn't they create a true
BeforeInsert event for inserting the WHOLE and completed
record, and a separate BeforeInsertTemporaryNewRecord
event which fires upon entry of your first character?
Insert just creates the place holder, it doesn't actually put anything into
it. The update event is what adds the record. In my opinion, the
BeforeInsert actually should be triggered as soon as you enter the new
record. I guess Microsoft thought it would be better to wait until
something was entered just so the program wouldn't be creating these place
holders if it wasn't needed.
And is this temporary one-character record allowed to
ignore validation rules?
Which validation are you referring to. Validation of the teextbox or the
form. Validation of the textbox will occur when you hit tab, enter, click.
Validation of the record isn't triggered until you go past the last field or
save. If you want validation when you type the first character, try the
Dirty event.
Because, to me, inserting a
record means you want to have your newly entered data
verified against your validation rules. And having Insert
events should take this into consideration. It appears
they don't. I can't think of a single reason I'd want to
put any kind of code in a BeforeInsert event, as there
would be no data in the new record except for the first
character typed. What is there to validate? What is the
point?
None. Validation doesn't occur at this point. See above.
And finally, does this BeforeInsert event work the same
way on a form bound to SQL Server data? My issue is
simple, I want my users to enter a new record, and I want
it validated before being permanently inserted, and I want
the user warned if they missed something or broke a
validation rule. (And I want to avoid the design overhead
of an unbound form, a SAVE button and pages of code to
manually validate).
BeforeUpdate works well, except that when I use the Access
intrinsic constant acDataErrContinue as the value of the
Response argument (to disable the Access warning message
and use my own customized message), the user is returned
to their new record but it is blank. All the information
they entered is gone (quite a few fields) and they'd have
to start over.
Are you sure you are returning to the same new record or is this going to
another new record. If you continue an error, it just ignores the error and
continues what it was doing. So if this is occuring while you are updating
the record (ie making it permanent), continuing through the error will
continuing saving the new record and take you to the next new record.
Sigh. This all used to work so well with Jet.
I would remove the validation from the properties section and put them in
the events instead. If you want to check each character, use the change
event of the textbox, if you want to check the entire value, use the
beforeupdate event of the textbox and to check all fields in one time, use
the beforeupdate of the form. Instead of continuing through the error,
cancel the update using Cancel=True. Good luck.
Kelvin