B
BizMark
I'm planning to write a workbook with a suite of macros and 'plan'
userforms which use data from 'outboard' workbooks to present that data
within them, as forms.
As part of this I want to be able to specify 'form' templates that
depending on the 'field' types chooses to display each 'record' (i.e.
row) as a series of edit boxes, dropdowns, combos etc. according to
what is relevant for the type of data in each field.
Rather than design lots of different permutations of forms for this
purpose, I want to be able to create each form dynamically through
code, so that the source data determines how the form will look and how
many controls it will have.
So far, I have no problem with this - I have added controls through
code many times and am fairly comfortable with that side of things.
HOWEVER - this is the big sticking point - I want to be able to assign
EVENTS to these dynamically created controls, and I can't find a way to
do it. Remember that I don't want to have to assume what all the
control names are going to be and when they are going to present or
not. Therefore, I don't want to have to 'pre-write' event code for
every possible control name that there will ever be.
What I want to be able to do however is write some 'generic' event
routines, that perhaps I can attach to invisible or 'off-form' controls
of each given type that I will use (so that parameter declarations
compile OK) and then 'duplicate' these for new controls at runtime. I
keep telling myself this is a solution that surely must have been
required by many programmers, but I can't find any help on this topic,
and all documentation about event routines seems to point to having to
create the control first, then write the event code second.
It was simple with Dialogsheets - simply setting the .OnAction property
to any macro you like - although of course you didn't get
system-generated parameters sent to the routine to work with like
events have.
So, is there a way of doing this with UserForm controls? If so, does
it involve lots of Declares of DLLs and stuff and registering them? I
hope not.
Anyone with a solution will receive my sincerest appreciation!
BizMark
userforms which use data from 'outboard' workbooks to present that data
within them, as forms.
As part of this I want to be able to specify 'form' templates that
depending on the 'field' types chooses to display each 'record' (i.e.
row) as a series of edit boxes, dropdowns, combos etc. according to
what is relevant for the type of data in each field.
Rather than design lots of different permutations of forms for this
purpose, I want to be able to create each form dynamically through
code, so that the source data determines how the form will look and how
many controls it will have.
So far, I have no problem with this - I have added controls through
code many times and am fairly comfortable with that side of things.
HOWEVER - this is the big sticking point - I want to be able to assign
EVENTS to these dynamically created controls, and I can't find a way to
do it. Remember that I don't want to have to assume what all the
control names are going to be and when they are going to present or
not. Therefore, I don't want to have to 'pre-write' event code for
every possible control name that there will ever be.
What I want to be able to do however is write some 'generic' event
routines, that perhaps I can attach to invisible or 'off-form' controls
of each given type that I will use (so that parameter declarations
compile OK) and then 'duplicate' these for new controls at runtime. I
keep telling myself this is a solution that surely must have been
required by many programmers, but I can't find any help on this topic,
and all documentation about event routines seems to point to having to
create the control first, then write the event code second.
It was simple with Dialogsheets - simply setting the .OnAction property
to any macro you like - although of course you didn't get
system-generated parameters sent to the routine to work with like
events have.
So, is there a way of doing this with UserForm controls? If so, does
it involve lots of Declares of DLLs and stuff and registering them? I
hope not.
Anyone with a solution will receive my sincerest appreciation!
BizMark