Re: handling a duplicate key error from field to field
- From: "J" <DamnYourSpam@xxxxxxxxx>
- Date: 13 Oct 2006 09:18:16 -0700
Private Sub txtItem_AfterUpdate()
If Dlookup("[IDField]","Table","[IDField]='" & txtItem & "'") <> 0
then
txtItem = ""
txtItem.Setfocus
Endif
End Sub
Why are you saving the record to update the field with a query? Why
don't you just set the control itself to what you want it to be? It's
a lot less taxing on the system if you use:
txtThirdField = Expression
As opposed to:
DoCmd.RunSQL "UPDATE Table "... blah blah blah
on the second field's afterupdate event.
Hope that helps,
~J
jaman57 wrote:
I have a form with three fields. The first is a text field where the user
names the item they are working on - this is a primary key, no dupes allowed.
The next field is a date field they fill in. On this date field I have an
"after update" event procedure to save the record (using DoCmd.RunCommand
acCmdSaveRecord) then runs an update query to populate the third field with
some data. It is necessary to do this at this point so the user sees the
result of the update. It doesn't work if the record is not saved first. The
problem is that after the "save record" code procedure, if the text they have
typed in the first field is a duplicate key they get the long-winded default
duplicate key message. I know how to create an error handling procedure that
after you get to the end of the form and try to move to the next record you
can have a custom error message and return them to the field that needs to be
changed. But this only attaches to the "on error" property for the form. I
have tried to create an error handler that will do the same kind of thing
after the field in question is updated, but with no success. I have tried to
follow some examples, but the result is always the same - the default
message. How can I accomplish what the form "on error" handling routine
accomplishes back after the field update?
Thanks,
Jeff
.
- Prev by Date: Re: Programmatically close a modal popup form
- Next by Date: Re: table in use
- Previous by thread: Re: Programmatically close a modal popup form
- Next by thread: Re: Dlookup not working
- Index(es):
Relevant Pages
|