1. Your code is opening a view called "(ShortName)" in names.nsf. That is not a standard view name in the template supplied by IBM. Did you create it in your Domino Directory? Is the first column sorted? Does the value in that column match your 'EmpCode' variable? Note: If you did add this view, you may not really need it. You could be using $Users, which includes the ShortName in the first sorted column, along with other values. The only reason you might not want to use $Users is if you need to be sure that the code values are definitely coming from the ShortName item in order to avoid potential conflicts. Of course, you could use $Users and also do an explicit doc.getItemValues("ShortName") and then double-check the (0)th entry for a match, and that would save you from having to maintain an extra view.
2. After your call to getDocumentByKey, you should be doing something like if doc is Nothing then... Relying on 'on error' is bad practice when you can avoid it. This is not causing your problem here, but it may be hiding it. You should always do explicit error checks whenever possible, because it makes your code much easier to debug. (Please note that I'm not saying you should never use 'on error'. In fact, you should almost always use it to handle problems that are truly unexpected, but not things like documents or items that are not found.)
3. And you should also be doing an explicit check of if doc.hasItem("DisplayName") before you do the doc.getItemValue("DisplayName"). In fact, in the standard names.nsf there is no item called DisplayName in Person documents, so my guess is that this is your problem -- or part of it -- and the 'on error' is hiding it from you. Yes, there is a field called 'DisplayName' in the Person form, but it is computed-for-display so the field is never stored as an item. You should probably be using FullName instead of DisplayName, since that's how the computed-for-display field formula for DisplayName gets its value.
I'd say it's even money on either #1 or #3 being your problem, but you should fix all three issues.
Error in code (Meena Ramesh 11.Jul.12)
Feedback response number WEBB8W4RYS created by Rich Schwartz on 07/11/2012
. . Several things (Rich Schwartz 11.Jul.12)
. . . . Conclusion (Meena Ramesh 12.Jul.12)
. . . . . . The code still got a number of issu... (Karl-Henry Mart... 12.Jul.12)
. . . . I'd click "Like" on this response i... (Phil M Jones 12.Jul.12)
. . Data Types (Pete Burn 11.Jul.12)
. . . . Reply (Meena Ramesh 11.Jul.12)
. . . . . . Try this... (Karl-Henry Mart... 12.Jul.12)
. . . . . . 1 character missing (Phil M Jones 11.Jul.12)
. . . . . . . . Stll problem persists (Meena Ramesh 11.Jul.12)
. . . . . . . . . . Have you tried the debugger? (Phil M Jones 11.Jul.12)