Using early or late binding

When doing VBA automation between Office applications, e.g. calling Excel from MS Access, using Outlook to send Emails from Excel, or using special libraries such as FSO for a more sophisticated access to the file system, you need to decide whether you will set a reference to the external client or library - early binding. Alternatively, you can use the other application using late binding using CreateObject or GetObject.

A significant disadvantage of late binding is that the VBE editor - and the Code VBA add-in - can't give IntelliSense support for the classes of the external application because they don't have access to the type information of the other client's classes. Also, code can not be checked by the compiler, giving a high risk of getting run-time errors and grumbling users. Finally, early-bound code simply is at least twice as fast!

Microsoft recommends early binding in almost all cases - a more detailed discussion is available here....

vba user defined type not defined error

If you use early binding code and a reference is not set you will get compile error 'user defined type not defined'. To fix this you will have to add the required reference. Code VBA tools add the reference needed automatically when inserting code - if default early binding behaviour is set. See Preferences - Choose Early or Late Binding.

Note: A reason to use late binding can be when you distribute an Access database in the ACCDE (or MDE) format. This may prevent getting an error when the database is opened on a machine with an earlier Office version.