O'Reilly logo

Access™ 2007 VBA Programmer's Reference by Armen Stein, Geoffrey Griffith, Rob Cooper, Teresa Hennig

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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# ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required