Microsoft KB Archive/224349

= ACC97: Code from "Building Applications Manual" Requires Office 8.0 Object Library =

Article ID: 224349

Article Last Modified on 1/24/2007

-

APPLIES TO


 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q224349





Advanced: Requires expert coding, interoperability, and multiuser skills.



SYMPTOMS
On pages 35 through 37 of the Building Applications with Microsoft Access 97 manual, there is a discussion titled "Working with Command Bars in Code." If you try to implement the code within this section of the manual, you may receive the following error message:

Compile error:

User-defined type not defined.



CAUSE
The Building Applications with Microsoft Access 97 does not explain that in order for the code to work, you must create a reference to the necessary external library.



RESOLUTION
Reference the Microsoft Office 8.0 Object Library. To do this, open your code module in Design view, and then on the Tools menu, click References. Scroll down the list of references until you find Microsoft Office 8.0 Object Library. Click to select the check box for this reference, and then click OK to close the References dialog box.



Steps to Reproduce the Behavior
 In a new database, create a new module. On the Tools menu, click References and note that the three default references associated with a new database are:

Visual Basic For Applications

Microsoft Access 8.0 Object Library

Microsoft DAO 3.5 Object Library

Click Cancel to close the References dialog box.  In the new module, type or paste the following sample code provided by the Building Applications with Microsoft Access 97 manual: Option Compare Database Option Explicit

Private Sub AddInvoiceCommand Dim cb As CommandBar Dim ctl As CommandBarControl 'Set a reference to the Tools menu. Set cb = CommandBars!Tools 'Create new CommandBarControl object on the Tools menu and 'set a reference to it. Set ctl = cb.Controls.Add(Type:=msoControlButton) 'Set properties of the new command. With ctl .BeginGroup = True .Caption = "Print Invoice" .FaceID = 0 .OnAction = "=PrintInvoice" .Visible = False End With End Sub  Try to compile the code. Note that you receive the error message mentioned in the "Symptoms" section of this article.</ol>

<div class="references_section">