Trigger an event from code

B

Bill

Can I trigger an "After Update" event from
code? I have an application wherein a text box
gets updated from code and I'd like that event
to "fire". The identification of the text box is
contained in a control variable. That being the
case, I could just as well call the "After Update"
Sub if that's possible?

E.g., if the control variable tbCntl is set to "tbTopic"
and there's a "Private Sub tbTopic_AfterUdate()",
can I/how would I call the AfterUpdate code?

Thanks,
Bill
 
S

strive4peace

Hi Bill,

yes, you can

if you are in the class module that the code is in, simply call it by
its name

ie:

Private Sub tbTopic_AfterUdate()
'statements
End sub

then, somewhere else in the module -->

tbTopic_AfterUdate



Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*
 
A

Allen Browne

Try:
Call tbTopic_AfterUdate

If you are trying to trigger this from a different module, remove the
Private keyword from the sub line, and use:
Call Form_Form1.tbTopic_AfterUdate
replacing the "Form1" part with the name of your form.
(You see that module name in the Title bar of your VBA window.)
 
M

Marshall Barton

Bill said:
Can I trigger an "After Update" event from
code? I have an application wherein a text box
gets updated from code and I'd like that event
to "fire". The identification of the text box is
contained in a control variable. That being the
case, I could just as well call the "After Update"
Sub if that's possible?

E.g., if the control variable tbCntl is set to "tbTopic"
and there's a "Private Sub tbTopic_AfterUdate()",
can I/how would I call the AfterUpdate code?


AXP and later have the CallByName function that can do that.
 
B

Bill

Sorry, I didn't explain myself well enough......
At the time I want the AfterUpdate code to
fire for any one of several text boxes, the only
information I have about the text box is
its control name in the control variable
tbCntl.

So, do I: "Call tbCntl_AfterUpdate"

Bill
 
S

strive4peace

Hi Bill,

why do you want to make the called function a variable? Is the code
doing the same thing, just to a different control? If so, you can use
ActiveControl in your code and make it generic

in any case, each control will need to have a function or [Event
Prcedure] assigned to it in the property sheet

Can you give an example of where you are going with this?


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*
 
B

Bill

Crystal,
See my post "Using control variable in a call" earlier
today (Monday). There you'll see what I'm doing.
Bill



strive4peace said:
Hi Bill,

why do you want to make the called function a variable? Is the code doing
the same thing, just to a different control? If so, you can use
ActiveControl in your code and make it generic

in any case, each control will need to have a function or [Event Prcedure]
assigned to it in the property sheet

Can you give an example of where you are going with this?


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*


Sorry, I didn't explain myself well enough......
At the time I want the AfterUpdate code to
fire for any one of several text boxes, the only
information I have about the text box is
its control name in the control variable
tbCntl.

So, do I: "Call tbCntl_AfterUpdate"

Bill
 
S

strive4peace

Hi Bill,

Dirk gave you good advice.

If your code can be written generically (ie: for the activecontrol as
opposed to a specif control), we could help you with that if you would
tell us the code that you are using.

What kind of an application are you building? What do the textboxes
that you want to have AfterUpdate code for have in common?

Your controls must have something in common and that is the reason, I
suspect, that you want to make this a variable. You need an AfterUpdate
event for each control regardless of how you handle it in code ... it
still needs a "trigger"

If you give us more information, we can help you further.


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*


Crystal,
See my post "Using control variable in a call" earlier
today (Monday). There you'll see what I'm doing.
Bill



strive4peace said:
Hi Bill,

why do you want to make the called function a variable? Is the code doing
the same thing, just to a different control? If so, you can use
ActiveControl in your code and make it generic

in any case, each control will need to have a function or [Event Prcedure]
assigned to it in the property sheet

Can you give an example of where you are going with this?


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*


Sorry, I didn't explain myself well enough......
At the time I want the AfterUpdate code to
fire for any one of several text boxes, the only
information I have about the text box is
its control name in the control variable
tbCntl.

So, do I: "Call tbCntl_AfterUpdate"

Bill



Can I trigger an "After Update" event from
code? I have an application wherein a text box
gets updated from code and I'd like that event
to "fire". The identification of the text box is
contained in a control variable. That being the
case, I could just as well call the "After Update"
Sub if that's possible?

E.g., if the control variable tbCntl is set to "tbTopic"
and there's a "Private Sub tbTopic_AfterUdate()",
can I/how would I call the AfterUpdate code?

Thanks,
Bill
 
M

Marshall Barton

Have you tried my earlier suggestion about using the
CallByName function?
--
Marsh
MVP [MS Access]

Crystal,
See my post "Using control variable in a call" earlier
today (Monday). There you'll see what I'm doing.
Bill



strive4peace said:
Hi Bill,

why do you want to make the called function a variable? Is the code doing
the same thing, just to a different control? If so, you can use
ActiveControl in your code and make it generic

in any case, each control will need to have a function or [Event Prcedure]
assigned to it in the property sheet

Can you give an example of where you are going with this?


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*


Sorry, I didn't explain myself well enough......
At the time I want the AfterUpdate code to
fire for any one of several text boxes, the only
information I have about the text box is
its control name in the control variable
tbCntl.

So, do I: "Call tbCntl_AfterUpdate"

Bill



Can I trigger an "After Update" event from
code? I have an application wherein a text box
gets updated from code and I'd like that event
to "fire". The identification of the text box is
contained in a control variable. That being the
case, I could just as well call the "After Update"
Sub if that's possible?

E.g., if the control variable tbCntl is set to "tbTopic"
and there's a "Private Sub tbTopic_AfterUdate()",
can I/how would I call the AfterUpdate code?

Thanks,
Bill
 
B

Bill

Thanks for your thoughts Crystal. And yes, I essentially followed
Dirk's suggestion in that each of the text boxes have AfterUpdate
procedures and I simply "case select" the name in order to call
them.

To answer your question, one of the application's forms has several
text boxes lined up where the user can either type in a name or double-
click the text box and select from a combo box that acts like a pop-up
in that it suddenly becomes visible already dropped down. After the
user makes a selection, the selection is inserted into the text box and
the combo disappears. For this particular application, it was more
user-friendly to handle the data in this fashion than to force the use
of combos in place of the text boxes. The code issue was how to best
accomplish the triggering of AfterUpdate event for the text box
involved, since setting the text box in code does not cause that event
to fire.

Bill


strive4peace said:
Hi Bill,

Dirk gave you good advice.

If your code can be written generically (ie: for the activecontrol as
opposed to a specif control), we could help you with that if you would
tell us the code that you are using.

What kind of an application are you building? What do the textboxes that
you want to have AfterUpdate code for have in common?

Your controls must have something in common and that is the reason, I
suspect, that you want to make this a variable. You need an AfterUpdate
event for each control regardless of how you handle it in code ... it
still needs a "trigger"

If you give us more information, we can help you further.


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*


Crystal,
See my post "Using control variable in a call" earlier
today (Monday). There you'll see what I'm doing.
Bill



strive4peace said:
Hi Bill,

why do you want to make the called function a variable? Is the code
doing the same thing, just to a different control? If so, you can use
ActiveControl in your code and make it generic

in any case, each control will need to have a function or [Event
Prcedure] assigned to it in the property sheet

Can you give an example of where you are going with this?


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*



Bill wrote:
Sorry, I didn't explain myself well enough......
At the time I want the AfterUpdate code to
fire for any one of several text boxes, the only
information I have about the text box is
its control name in the control variable
tbCntl.

So, do I: "Call tbCntl_AfterUpdate"

Bill



Can I trigger an "After Update" event from
code? I have an application wherein a text box
gets updated from code and I'd like that event
to "fire". The identification of the text box is
contained in a control variable. That being the
case, I could just as well call the "After Update"
Sub if that's possible?

E.g., if the control variable tbCntl is set to "tbTopic"
and there's a "Private Sub tbTopic_AfterUdate()",
can I/how would I call the AfterUpdate code?

Thanks,
Bill
 
B

Bill

Hi Marsh,
Sorry I didn't post back on that. I need to keep this
particular application at A2K, so I didn't pursue that
idea.

For future reference, I would like to know how that
works. Given the control variable tbcntl "set" to a
text box control, how would I use it to call the
AfterUpdate procedure for current tbcntl.name
text box?

Bill


Marshall Barton said:
Have you tried my earlier suggestion about using the
CallByName function?
--
Marsh
MVP [MS Access]

Crystal,
See my post "Using control variable in a call" earlier
today (Monday). There you'll see what I'm doing.
Bill



strive4peace said:
Hi Bill,

why do you want to make the called function a variable? Is the code
doing
the same thing, just to a different control? If so, you can use
ActiveControl in your code and make it generic

in any case, each control will need to have a function or [Event
Prcedure]
assigned to it in the property sheet

Can you give an example of where you are going with this?


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*



Bill wrote:
Sorry, I didn't explain myself well enough......
At the time I want the AfterUpdate code to
fire for any one of several text boxes, the only
information I have about the text box is
its control name in the control variable
tbCntl.

So, do I: "Call tbCntl_AfterUpdate"

Bill



Can I trigger an "After Update" event from
code? I have an application wherein a text box
gets updated from code and I'd like that event
to "fire". The identification of the text box is
contained in a control variable. That being the
case, I could just as well call the "After Update"
Sub if that's possible?

E.g., if the control variable tbCntl is set to "tbTopic"
and there's a "Private Sub tbTopic_AfterUdate()",
can I/how would I call the AfterUpdate code?

Thanks,
Bill
 
B

Bill

Hummmm
I tried: CallByName tbcntl, "tbcntl.name_AfterUpdate", VbMethod
And: CallByName tbcntl, "AfterUpdate", VbMethod

on my 2003 system, but I get method not supported error.

Bill



Bill said:
Hi Marsh,
Sorry I didn't post back on that. I need to keep this
particular application at A2K, so I didn't pursue that
idea.

For future reference, I would like to know how that
works. Given the control variable tbcntl "set" to a
text box control, how would I use it to call the
AfterUpdate procedure for current tbcntl.name
text box?

Bill


Marshall Barton said:
Have you tried my earlier suggestion about using the
CallByName function?
--
Marsh
MVP [MS Access]

Crystal,
See my post "Using control variable in a call" earlier
today (Monday). There you'll see what I'm doing.
Bill



Hi Bill,

why do you want to make the called function a variable? Is the code
doing
the same thing, just to a different control? If so, you can use
ActiveControl in your code and make it generic

in any case, each control will need to have a function or [Event
Prcedure]
assigned to it in the property sheet

Can you give an example of where you are going with this?


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*



Bill wrote:
Sorry, I didn't explain myself well enough......
At the time I want the AfterUpdate code to
fire for any one of several text boxes, the only
information I have about the text box is
its control name in the control variable
tbCntl.

So, do I: "Call tbCntl_AfterUpdate"

Bill



Can I trigger an "After Update" event from
code? I have an application wherein a text box
gets updated from code and I'd like that event
to "fire". The identification of the text box is
contained in a control variable. That being the
case, I could just as well call the "After Update"
Sub if that's possible?

E.g., if the control variable tbCntl is set to "tbTopic"
and there's a "Private Sub tbTopic_AfterUdate()",
can I/how would I call the AfterUpdate code?

Thanks,
Bill
 
M

Marshall Barton

That should be:

CallByName Me, tbcntl.Name & "_AfterUpdate", VbMethod

and don't forget that the event procedures you want to call
this way must be Public.
 
B

Bill

"this way must be Public" even if the CallByName is
issued within the same code sheet as the procedure
being called?



Marshall Barton said:
That should be:

CallByName Me, tbcntl.Name & "_AfterUpdate", VbMethod

and don't forget that the event procedures you want to call
this way must be Public.
--
Marsh
MVP [MS Access]

I tried: CallByName tbcntl, "tbcntl.name_AfterUpdate", VbMethod
And: CallByName tbcntl, "AfterUpdate", VbMethod

on my 2003 system, but I get method not supported error.
 
M

Marshall Barton

It appears(?) that the CallByName mechanism operates
somewhere outside the caller's class module, somewhere where
only public names are known. Somewhat irritating, but not a
particularly big deal, especially considering how often a
class module's properties and methods are private.
 
B

Bill

Hi Marsh,
Indeed it must! Just to experience what happens, I left
one of the AfterUpdate procedures as Private....BOOM!
As soon as I changed it to Public, everything worked
as desired.
Thanks,
Bill



Marshall Barton said:
It appears(?) that the CallByName mechanism operates
somewhere outside the caller's class module, somewhere where
only public names are known. Somewhat irritating, but not a
particularly big deal, especially considering how often a
class module's properties and methods are private.
--
Marsh
MVP [MS Access]

"this way must be Public" even if the CallByName is
issued within the same code sheet as the procedure
being called?


"Marshall Barton" wrote
 
S

strive4peace

thanks, Marshall!

Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*
 

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