Hi J Allen,
Yes indeed and these ones are fun to watch run: An update query. Make a backup copy of your table just in case...
Make a simple query that is based off of the table with your imported records. Drag your code field to the grid. In the criteria row your criteria should look something like: Forms![NameofForm]![NameofFieldWithBadCode]
You can even run the query now (with data in the form) just as a test.
Now choose Query type from the tool bar- Update Query.
You just gained a row in the grid that says "Update to".
In this row underneath your code field you should have something like: Forms![NameOfForm]![NameofFieldWithGoodCode]
Again, you can run a test (with data in the form), by clicking the query datasheet view, Not the ! button which will commit the action. You won't see the change, but you should see if anything "disagrees" with Access.
Save the query.
I would put a command button on the form to do this but you could certainly run it in the after update event of both fields on the form. Something like:
On error goto Err1
If IsNull(Me![NameofFieldWithGoodCode]) Or Me![NameofFieldWithGoodCode] = "" Then
MsgBox "There's nothing in the good code!",vbinformation
Exit sub
end if
'optional depending on your needs
If IsNull(Me![NameofFieldWithBadCode]) Or Me![NameofFieldWithBadCode] = "" Then
MsgBox "There's nothing in the bad code!",vbinformation
Exit sub
end if
'end of optional
DoCmd.setWarnings False 'if you don't want to see messages
Docmd.OpenQuery "NameofyournewQuery"
Exit1:
Docmd.setWarnings True
me.Requery
Exit Sub
Err1:
Msgbox Err.Number & " " & Err.Description,VbInformation,"Ooops"
Resume Exit1
The official way to do this if you want to run it from the after update of either field is to make it a "Private Sub" on its own: Private Sub FixMyCode()
'all the stuff above in here before the "End Sub"
Then in the After update event of each field (in visual basic as well), type in: FixMyCode
Should do it but best is to try on a copy of your table to make sure nothing blows up! ;-) Gord
ghubbell@total.net