Thank you in advance
Answer:What is happening is that Iif will always evaluate (run) both parts. So the last part will throw an exception since Id_Padre is nothing. From documentation (https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/iif-function):
IIf always evaluates both truepart and falsepart, even though it returns only one of them. Because of this, you should watch for undesirable side effects. For example, if evaluating falsepart results in a division by zero error, an error occurs even if expr is True.
I recommend using If instead to avoid this (https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/if-operator) so:
If you have better answer, please add a comment about this, thank you!