Re: handling a duplicate key error from field to field

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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

.



Relevant Pages

  • RE: Need to set Filters on a form based on several drop down boxes
    ... can you see something wrong with the SQL statement? ... Private Sub psBuildSQL() ... "Jack Leach" wrote: ... know that saved queries will always run faster than a "built" query. ...
    (microsoft.public.access.modulesdaovba)
  • Re: access 2003
    ... I've noticed is that it seems you should be using a parameter query to ... Dim db As DAO.Database ... then the recordset contains no records: ... Private Sub ChooseCust_AfterUpdate ...
    (microsoft.public.access.conversion)
  • Re: Emailing from a form using recursive query results
    ... A query that uses the retrieves from anothr relation the ... A single Emailaddress is generated for this ... Static myValue as Integer 'I would actually type this as whatever ... Private sub Form_Current ...
    (microsoft.public.access.forms)
  • Re: How to fix Error 2465
    ... Doug Steele, Microsoft Access MVP ... The main query is... ... Private Sub Contact_Type_BeforeUpdate ... I tried your code (though had to put a " in after the [ContactID] to ...
    (microsoft.public.access.formscoding)
  • Re: How to fix Error 2465
    ... Hi Doug - I'm going to sit with this fix for a while and try and nut it out. ... Doug Steele, Microsoft Access MVP ... The main query is... ... Private Sub Contact_Type_BeforeUpdate ...
    (microsoft.public.access.formscoding)