Microsoft KB Archive/286595

= ACC2002: Error When You Run RecordExit Function or Sub Procedure =

Article ID: 286595

Article Last Modified on 9/26/2003

-

APPLIES TO


 * Microsoft Access 2002 Standard Edition

-



This article was previously published under Q286595



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

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).



SYMPTOMS
When you open a form in browse mode, and then run any code on that form, you may receive the following error message

The expression  you entered as the event property setting produced the following error: Procedure declaration does not match description of event or procedure having the same name.


 * The expression may not result in the name of a macro, the name of a user-defined function, or an [Event Procedure].


 * There may have been an error evaluating the function, event, or macro.

where  is the event from which you attempted to run the code.

When you compile the project, you receive the following error message:

Compile Error:

Procedure declaration does not match description of event or procedure having the same name.

The following line appears highlighted as the cause of the compile error: Sub Form_RecordExit



CAUSE
This issue occurs when a Sub procedure or function is named Form_RecordExit. This name overlaps a hidden Access form event named RecordExit, which requires a specific syntax.

Although you can create an event procedure to run against this event without harming your form behavior, you must provide the correct parameter syntax when you call the procedure. Without the correct syntax, the project does not compile, and any code that you run on the form returns the error message described in the &quot;Symptoms&quot; section.



RESOLUTION
To resolve this issue, use either of the following methods:

 Rename the Sub procedure or function, and change any code that references it. This is the preferred method.

-or-

  If you must use the name Form_RecordExit, change the declaration syntax of the Sub procedure or function, and change the syntax of any calls to the procedure to provide the correct parameters.

To change the declaration, use the following syntax: Sub Form_RecordExit(Cancel as Integer) 'User Code Here End Sub To properly call the code, use the following syntax, which includes a parameter: Sub MySub Call Form_RecordExit(0) 'Other User Code Here End Sub 



MORE INFORMATION
In Microsoft Access 2002, the object model for forms contains a hidden event named RecordExit. Because the event is hidden, it does not appear in the Property list for the form object in the Visual Basic Environment (VBE). However, if you write a Sub procedure named Form_RecordExit, the procedure does not work unless it uses a specific syntax.

This hidden event did not exist in Microsoft Access 2000 or earlier.

If you write a project in Access 2000 and then open it in Access 2002, Access silently uncompiles the project. You do not receive any notification until you open the form and attempt to run Microsoft Visual Basic for Applications (VBA) code in it, or until you try to recompile the project.

