Yes, thank you. I just noticed that your code is in an OnAfterChange event handler, so you don't need a loop.
Please try the following:
Replace
empid = XDocument.DOM.selectSingleNode("//my:Prefix").Text
with
empid = eventObj.Site.text
And replace
XDocument.DOM.selectSingleNode("//my:FirstName").Text = oRecordSet.fields & _
("givenname")
XDocument.DOM.selectSingleNode("//my:LastName").Text = oRecordSet.fields("sn")
XDocument.DOM.selectSingleNode("//my:UnitCode").Text = left(oRecordSet.fields & _
("department"), 5)
With
eventObj.Site.selectSingleNode("../my:FirstName").Text = oRecordSet.fields & _
("givenname")
eventObj.Site.selectSingleNode("../my:LastName").Text = oRecordSet.fields("sn")
eventObj.Site.selectSingleNode("../my:UnitCode").Text = left(oRecordSet.fields & _
("department"), 5)
That should do what you want it to do.
Just as a comment, the auto-generated part:
If eventObj.IsUndoRedo Then
' An undo or redo operation has occurred and the DOM is read-only.
Exit Sub
End If
should really be at the top of the subroutine, not at the bottom.