Access™ 2007 VBA Programmer's Reference
by Teresa Hennig, Rob Cooper, Geoffrey Griffith, Armen Stein
C.2. Writing Managed Code
To write managed code for use in Access, you can use one of the Visual Studio editions such as Visual Studio 2005, Visual Basic 2005 Express Edition, or Visual C# 2005 Express Edition. There are two distinctly different approaches you can take when writing managed code for use in Access:
Write a class library that defines classes that you can reference from your Access application.
Write a COM add-in that contains user interface code and allows you to launch it when Access starts.
The following sections explore both of these approaches.
C.2.1. Class Libraries
When you write a class library using managed code, Visual Studio creates a DLL for you that contains the classes you have defined. However, the DLL is actually an assembly managed by the CLR. Because the DLL contains managed code, referencing it in Access produces an error, as shown in Figure C-1.
Instead, the .NET Framework allows you to create a type library that you can reference from VBA. These type libraries are compatible with COM applications such as Access.
If you want to extend your Access application to write to the Windows event log, for example, you could use the Windows API or the EventLog class in the .NET Framework, which is much simpler to write.
Figure C.1. Figure C-1
The examples in this appendix were created using Visual Studio 2005, but can also be created using the Visual C# ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access