Apologies, sir or madam, I did not mean to cause offense, or to imply that there as anything wrong with the code.
no offence taken, but we provide suggestions rather than solutions and unless you provide us with the code you are actually using, together with other things like table names, field types, we can only provide 'something like'.
What you did here is the right thing to do - but you need to check names are correct etc
2) I selected the "build" option, chose "code builder," and pasted the text you provided into the resulting window, between the "Private Sub Spouse_LastName_AfterUpdate()" and "End Sub" lines.
Result: On update, no error messages of any kind were created. However, on examning the table afterwards, the contents of the Spouse-LastName field had not been removed
So you should have had this
Code:
Private Sub Spouse_LastName_AfterUpdate()
if Spouse-LastName=HoH-LastName then Spouse-LastName=null
End Sub
and if it didn't work, rather that just saying it didn't work, post the code you had actually used plus this comment
Result: On update, no error messages of any kind were created. However, on examning the table afterwards, the contents of the Spouse-LastName field had not been removed.
I'm going to have to guess from here as to what is wrong.
You will notice that the sub name is not Spouse-LastName_AfterUpdate(), but Spouse_LastName_AfterUpdate() - vba has replaced the - with a _.
One of the problems with using non alpha numeric characters is they can cause unexpected errors. In this case when you pasted the code directly into the vba window, I'm guessing the - sign was reinterpreted and spaces added (i.e. vba assumed it was a calculation) so
Spouse-LastName
became
Spouse - LastName
and similarly for the other field. As explained their use can cause unexpected errors, and I guess this is one of them.
my other guess is that you do not have Option Explicit set in your code window (just below Option Compare Database) which would have picked this up as an error.
I'm guessing again, that you then put some brackets round the name, but now it has spaces - so still not valid, and without Option Explicit, VBA just treats as an undeclared variable, executes the line but it does nothing.
As I said, this is guesswork as to why it is not working. Please let me know if my guesses are correct by repeating the copy paste and the subsequent steps if necessary. If correct, remove the spaces from the resultant names and try again, if that doesn't work, change the - to a _ and try again. better still, remove the - from your field and control names, use an _ instead if you have to.
Once you've done that, if it is still not working, come back with the code used and confirm the names of your table fields and form controls - in your first post you said
I've tried things like "<>[HoHLastName]
and in subsequent post you used HoH-LastName