This error comes because you have missed to install Microsoft Visual Studio Tools for Application (VSTA). To add VSTA to Microsoft Office, follow the steps.
1.Go to Control Panel -> Programs and Features.
2. Select Microsoft office version and click Change. You will get a screen like this.
3. Select Add or Remove Features and Continue.
4. Expand Microsoft InfoPath, .Net Programmability support. Under Visual Studio Tools for Application select Run From My Computer and Continue. See the screen.
Once you followed the steps you will be able to add managed code in InfoPath 2010.