Passing arguments to a function in an event handler

  • Thread starter Thread starter sjg1314
  • Start date Start date
S

sjg1314

I'd like to be able to set up an event handler for the On Error event.
I want to do this programmatically.

I know the event handler needs to be a function and that it looks
something like "=MyFunc()". But the On Error event supplies two
arguments, DataErr and Response, which I need to access.

So I wrote a function that starts like this:

Public Function errorHandler(DataErr As Integer, Response As Integer)

Using the Expression Builder, I select the function, click OK and the
On Error property gets:

=errorHandler([«DataErr»],[«Response»])

This doesn't work. Nor does "=errorHandler([DataErr],[Response])".I've
tried a number of other variants with no success, so I'm hoping someone
here knows the right way to do this, or knows that it can't be done.

Thanks.
 
try calling your custom function from within the form's module rather than
from the form's Properties event line, as

Private Sub Form_Error(DataErr As Integer, Response As Integer)

errorHandler DataErr, Response

End Sub

hth


I'd like to be able to set up an event handler for the On Error event.
I want to do this programmatically.

I know the event handler needs to be a function and that it looks
something like "=MyFunc()". But the On Error event supplies two
arguments, DataErr and Response, which I need to access.

So I wrote a function that starts like this:

Public Function errorHandler(DataErr As Integer, Response As Integer)

Using the Expression Builder, I select the function, click OK and the
On Error property gets:

=errorHandler([«DataErr»],[«Response»])

This doesn't work. Nor does "=errorHandler([DataErr],[Response])".I've
tried a number of other variants with no success, so I'm hoping someone
here knows the right way to do this, or knows that it can't be done.

Thanks.
 
Hi, Tina,

Thanks for taking the time to respond, but I'm afraid your answer
doesn't help. I know how to call functions from a standard event
handler.

Although in the example I gave I talked about entering a function in
the Properties window, I may also want to set this up programmatically.
For instance, I might want to step through all the controls in a Form
and add a handler for each one. Having to code a Form method to make
this work defeats the purpose.

If anyone has an answer to my original question or can tell me that it
is not possible, I'm still interested.

I want to set these handlers programmatically.
 
Back
Top