Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Progammatically attach code to a form control

Status
Not open for further replies.

aliendan

Programmer
Jun 28, 2000
79
US
In my database, upon a certain condition and a certain event, it progammatically creates a form with an optiongroup on it. The optiongroup's toggle button's captions are derived from a tables 'name' field and the optionvalues are derived from said table's 'autonumber' field. Now I need to programmatically insert code into the optiongroups afterupdate event to do "whatever....". Can this be done? If so, how?
Dan Rogotzke
Dan_Rogotzke@oxy.com
 
I've created wizards that generate code for me. The following is some code I pulled out and stripped out a bunch of stuff. Haven't tested it, but should give you an idea of how to do it.
Code:
    Dim mdl As Module
    Dim strCode as String
    
    Set mdl = Modules("NameofModule")
    strCode = "TheCodeYouWantToInsert"
    mdl.InsertText strCode
 
Thanks, FancyPrairie, for you input. It led me in the right direction. What I ended up doing was create a public sub called "SetDefaultDistrict" that has all the code I need for the optiongroup to do it's thing then included this code along with the creation of the optiongroup which inserted the call procedure into the afterupdate event:

Dim mdl As Module, lngReturn As Long

Set mdl = frm.Module
lngReturn = mdl.CreateEventProc("AfterUpdate", opt.Name)
mdl.InsertLines lngReturn + 1, vbTab & "Call SetDefaultDistrict"

This was much easier than inserting all the code it needed (which I did first...but it was just too messy...even though it worked too).

This works great. Thanks again.
Dan Rogotzke
Dan_Rogotzke@oxy.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top