View Full Version : Solved: Assign Macro to Runtime-Generated Textbox Event
duluter
08-12-2009, 11:53 AM
Hi, all.
If I add a textbox to a userform at runtime. How do I assign a macro to run when the textbox's AfterUpdate event fires?
Thanks,
Duluter
Bob Phillips
08-12-2009, 11:57 AM
Don't add it aruntime, add it in design and hide it until required.
duluter
08-12-2009, 06:33 PM
Thanks for the reply, xld.
I suppose it's possible for me to unhide existing controls at runtime, but I'm generating a dynamic form based on runtime conditions. I do not know how many textboxes I might need at runtime. I guess I could create more than I think I'll ever need, but that seems inelegant. My only roadblock right now is tapping into the runtime-generated control events. If there's a way to do it, then I'd like to go that route. Is there no way?
Thanks,
Duluter
mikerickson
08-12-2009, 09:33 PM
One way to code events for on the fly controls is to use a custom class.
The code in This Post (http://www.vbaexpress.com/forum/showthread.php?t=27542&highlight=control+class) shows how its done with checkboxes.
In your case, you could write a class for textboxes, but there is no AfterUpdate event in a custom class. Perhaps a different TextBox event (that is avalible via classes) would work for your need.
Also, depending on how they are to be used, a list box (with its easily variable number of items) can sometimes be used rather than creating textboxes on the fly.
duluter
08-13-2009, 12:14 PM
Thank you, all. I'll see what I can do with the class module.
Duluter
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.