View Full Version : Problem using EVAL function


Schof
11-14-2002, 05:13 PM
When I use the EVAL function to execute a procedure in a form it executes the procedure twice. Does anyone know of a workaround or a fix for this?

For example:

On Click: =eval(Form_AfterUpdate)

where Form_AfterUpdate is a public procedure.


I tried to use the EVAL function in a popup menu to execute a procedure in a form but had the same result. Instead I had to use the SendKeys function but the problem with that is it only works for control with shortcuts defined.

Pat Hartman
11-14-2002, 07:08 PM
Access will execute the AfterUpdate event immediately after saving a record so it doesn't suprise me that the event runs twice. Once when it is supposed to and then again as a result of your click event.

You need to be very careful with code you put into a form's AfterUpdate event. It must NOT dirty the current record or you'll put Access into a loop.

Schof
11-15-2002, 07:41 AM
That procedure was just an example. In my application I have created popup menus and have set the action as
"=processShortcutMenu()". I have defined that function in a module as:

Public Function processShortcutMenu()
Dim cmdbarCtl As CommandBarControl

Set cmdbarCtl = CommandBars.ActionControl
Eval ("Forms(" & Chr$(34) & application.CurrentObjectName & Chr$(34) & ")." & cmdbarCtl.Tag)
End Function

The commandbar tag is the name of the procedure in the form that I want to run. This works but again, it runs mulitple times.

I am also trying to use this concept in other areas other than popup menus so it is very important for me to figure out how to do this.

Schof
11-21-2002, 06:54 PM
I knew there was a way to do it. Enjoy!!!

Public Function processShortcutMenu()
Dim frm As Form
Dim cmdbarCtl As CommandBarControl

Set cmdbarCtl = CommandBars.ActionControl
Set frm = Forms(application.CurrentObjectName)

CallByName frm, cmdbarCtl.Tag, VbMethod
End Function