Set control AfterUpdate event to procedure in another module

M

morleyc

Hi, i know i can set a controls AfterUpdate event to a user defined
procedure if it is in the same module as the code, however is it
possible to set it to a procedure in a different module? i.e. By
setting in the OnFormLoad() event:

cbo.AfterUpdate = "=Module1.Translate()"

I cant get it to work, it just says "the expression you entered has a
function name that microsoft office access cannot find". The Translate
procedure is public. Any thoughts much appreciated.

Thanks in advance,

Chris
 
A

Allen Browne

If Module1 is a standard module (not a class module, and not the module of a
form/report), and Translate() is a public function that is uniquely named
(not a Sub, not private, not ambiguous), you can just use:

cbo.AfterUpdate = "=Translate()"
 
S

Storrboy

Hi, i know i can set a controls AfterUpdate event to a user defined
procedure if it is in the same module as the code, however is it
possible to set it to a procedure in a different module? i.e. By
setting in the OnFormLoad() event:

cbo.AfterUpdate = "=Module1.Translate()"

I cant get it to work, it just says "the expression you entered has a
function name that microsoft office access cannot find". The Translate
procedure is public. Any thoughts much appreciated.

Thanks in advance,

Chris

Why not just call the function from the AfterUpdate event itself? Instead of
using it as the expression you are, use the event proceedure...

Private Sub cbo_AfterUpdate()
Call Translate
End Sub
 
M

morleyc

If Module1 is a standard module (not a class module, and not the module of a
form/report), and Translate() is a public function that is uniquely named
(not a Sub, not private, not ambiguous), you can just use:

cbo.AfterUpdate = "=Translate()"
Thanks Allen,

I think i may have it as a procedure... it is in a seperate module and
it is declared public. When you mention it im sure its a sub, i'm sure
subs work when they are in the same module of the form?

Cheers,

Chris
 
M

morleyc

Why not just call the function from the AfterUpdate event itself? Instead of
using it as the expression you are, use the event proceedure...

Private Sub cbo_AfterUpdate()
Call Translate
End Sub

Its complicated for a reason! I want a modularised combo filtering
code that is generic, seems VBA is a bit limiting. Ideally i would
like to have control events call directly into member methods but it
seems this is not possible. Im therefore left with no choice but an
event registration mechanism which calls back to a single function,
from where an identifier is used to work out which object the callback
is for... if that makes sense! once i can get the callback working it
will work.
 
D

Douglas J. Steele

Note, though, that the function doesn't have to return a value, so all you
have to do is change it from Sub to Function.
 
M

morleyc

You cannot use a Sub in an event property like that.
Functions only.

After wasting an entire afternoon yesterday thank you so much, it
indeed works now. I had to do this so i can register control events to
callback into class methods which will make my form code much more
modular! Thanks again

Thanks,

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top