Ata (may Allah have mercy on him) said regarding a man who has not performed Hajj and then performs Hajj intending a voluntary Hajj, or intending Hajj on behalf of another man, or intending Hajj to fulfil his vow: this will be his obligatory Hajj. After that, if he wishes, he may perform Hajj on behalf of the man or to fulfil his vow.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الحج / 8690