ACC2002: Argument Order Is Reversed When an Event Property Is a Function in Another Form's Class Module (282337)
The information in this article applies to:
This article was previously published under Q282337 Moderate: Requires basic macro, coding, and interoperability skills.
This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).
SYMPTOMS
When you set the event property of a control in one form to be a function that is declared in the class module of another form, the order in which the arguments is processed is reversed.
RESOLUTION
You can work around this behavior in either of two ways:
- Define the required function in a standard module rather than in a form's class module.
- Use the control's event procedure to call the function from another form, rather than setting the value of the function as the control's event property.
Method 1: Save the Function in a Standard Module
When functions need to be called from more than one form or other database object, it is often best to save them in standard modules. To use a function in a standard module, follow these steps:
- Create a new database named ArgTest.mdb.
- Create a new module from the Database window.
- In the Code window, enter the following function:
Function ArgListS(p1 As String, p2 As String, p3 As String) As String
ArgListS = p1 & p2 & p3
MsgBox ArgListS
End Function
- On the toolbar, click Save. Name the module ArgCode and close the Visual Basic Editor.
- Create a new form in Design view and add a command button with the following properties:
Name: PropertyS
Caption: PropertyS
On Click: =MsgBox("Arguments are " & ArgListS("P1","P2","P3"))
- Save the form as FormTest. On the View menu, click Form View.
- Click the PropertyS button.
The arguments appear in the expected order.
Method 2: Use an Event Procedure to Call a Function from Another Form's Class Module
If you do not want to relocate a form's function to a standard module, you can still call it from a different form, but you should use an event procedure to do so. To do that in this example, follow these steps:
- In the ArgTest.mdb file created in the first example, create a new form in Design view.
- On the View menu, click Code and enter the following function:
Function ArgListC(p1 As String, p2 As String, p3 As String) As String
ArgListC = p1 & p2 & p3
MsgBox ArgListC
End Function
- Close the Visual Basic Editor and save the form as FormCode.
- On the View menu, click Form View, and then minimize the form.
- Open the form FormTest in Design view.
- Add a new command button with the following properties:
Name: Procedure
Caption: Procedure
On Click: [Event Procedure]
- On the View menu, click Code and enter the following procedure:
Private Sub Procedure_Click()
MsgBox ("Arguments are " & Forms![FormCode].ArgListC("P1","P2","P3"))
End Sub
- Close the Visual Basic Editor, switch to Form view and click the Procedure button.
The arguments appear in the expected order.
STATUSMicrosoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. REFERENCESFor more information about standard modules and class modules, click Microsoft Access Help on the
Help menu, type module in the Office Assistant or
the Answer Wizard, and then click Search to view the topics
returned.
Modification Type: | Major | Last Reviewed: | 11/5/2003 |
---|
Keywords: | kbbug kbpending KB282337 |
---|
|