Userforms with CommandBar Popups

N

Neil

I've reposted this item as I answered the first post on this subject
myself and think therefore it may have got lost in background clutter.

I have created a class module that displays a treeview within a
userform. The treeview can display several data types. For example,
the user gets presented with a tree of service providers which are
indexed uniquely by name and country. If the user chooses to add a
new service provider, then he will be presented with a second userform
( a second instance of the same userform) that contains a treeview of
the countries they may choose from.

Each instance of the treeview userform creates a commandbar popup that
has awareness of the treeview content, for example, in the first
instance to select, add, rename or delete the service provider name,
and in the second instance to select, add, rename, delete a country.

From what I've understood from this forum and other sources, the
CommandBar Popup OnAction target can only reside in a general module.

So, my original problem still exists - how can I set things up so that
the general OnAction module knows which instance of the treeview
userform to act upon?

One idea, I guess, is to stack the objects that contain the userform
treeviews in a collection and key them on the userform caption - I
guess this is what Windows itself does?

If I could pass the OnAction module a parameter of the parent treeview
userform then it would be much easier.

Anyone have any ideas?

Many thanks......Neil
 
P

Peter T

I don't follow this
" Each instance of the treeview userform "
and
" how can I set things up so that
the general OnAction module knows which instance of the treeview
userform to act upon? "

There can only ever be one instance of a Userform. Not sure if you are
trying to say you have several 'similar' userforms or several class objects
(or both). Either way it should be pretty simple to get back to (ie call)
the required class or form from the popup macro. But explain how you've got
things set up, eg if you want to get back to say some class that's running
some form do you want to call the class or the form from the popup macro. If
relevant how and where are the main object references to the classes stored
(don't need to stuff about treeviews etc).

Regards,
Peter T
 
N

Neil

I don't follow this
"  Each instance of the treeview userform "
and
" how can I set things up so that
 the general OnAction module knows which instance of the treeview
 userform to act upon? "

There can only ever be one instance of a Userform. Not sure if you are
trying to say you have several 'similar' userforms or several class objects
(or both). Either way it should be pretty simple to get back to (ie call)
the required class or form from the popup macro. But explain how you've got
things set up, eg if you want to get back to say some class that's running
some form do you want to call the class or the form from the popup macro.If
relevant how and where are the main object references to the classes stored
(don't need to stuff about treeviews etc).

Regards,
Peter T

I apologise if my description is not clear - I'll try again:

There is one "user selection" userform that is initialised depending
on what attribute the user is working with. These can include, for
example, service providers, colours, countries, locations - anything
that can be represented as a hierarchical tree.

If the user is working with service providers, these are displayed in
what I referred to as the first instance of the userform. Service
providers have a second attribute of country, for example, Ford UK is
a differrent manufacturer to Ford US. Hence the same userform is
initialised to show countries for the user to select, This is what I
meant by the second instance of the userform. So the user now sees two
instances of the same userform, the first showing service provider
names and the second showing countries for them to select from.

Each userform allows the user to right mouse click and make a
selection. Within the service provider userform this will produce
options to rename, add or delete a service provider. Right mouse-
clicking within the countries userform will allow the user to
rename,add or delete countries.

By a lot of smoke and mirrors this is all working but not as elegantly
as I would like. If I should need to go to a 3rd level of userform in
the future then it's going to be even more difficult.

The major issue remains that, because I have to keep the CommandBar
popup menu OnAction target module as a general module, I do not
understand how to have that general module know which userform it's
talking to - if the user selects "delete", for example, am I deleting
a service provider or a country?

If the OnAction module was within the same Class module as the
userform, then this would take care of itself, bu it's obviously not.

Is this explanation any clearer?
 
P

Peter T

Again you say -

"So the user now sees two instances of the same userform"

I take it you mean the user sees two similar looking userforms, right?

Not to worry, I'm now starting to get the idea. There are several approaches
but the simplest (as in for me to suggest without knowing exactly what
you've got) is to assign a temporary object variable in a normal module with
a reference to the form, something like this

' in the form
Sub DoPopup
Set gObjFrm = Me
' code to create the popup
myPopupBar.ShowPopup
myPopupBar.Delete
Set gObjFrm = Nothing
end sub

' maybe you might want this
Public Sub MyProc() ' don't forget the public
' do stuff
End Sub

' in a normal module
Public gObjFrm as Object

Sub Macro1()
' directly work on a control
gObjFrm.SomeControl.SomeProperty = NewValue
'or maybe call a routine in the form
Call gObjFrm.MyProc

Set gObjFrm = Nothing ' or do that back in the form
End Sub

As I say, there may well be better approaches with more control and/or more
elegant ways, but something like the above should work.

Regards,
Peter T



I don't follow this
" Each instance of the treeview userform "
and
" how can I set things up so that
the general OnAction module knows which instance of the treeview
userform to act upon? "

There can only ever be one instance of a Userform. Not sure if you are
trying to say you have several 'similar' userforms or several class
objects
(or both). Either way it should be pretty simple to get back to (ie call)
the required class or form from the popup macro. But explain how you've
got
things set up, eg if you want to get back to say some class that's running
some form do you want to call the class or the form from the popup macro.
If
relevant how and where are the main object references to the classes
stored
(don't need to stuff about treeviews etc).

Regards,
Peter T

I apologise if my description is not clear - I'll try again:

There is one "user selection" userform that is initialised depending
on what attribute the user is working with. These can include, for
example, service providers, colours, countries, locations - anything
that can be represented as a hierarchical tree.

If the user is working with service providers, these are displayed in
what I referred to as the first instance of the userform. Service
providers have a second attribute of country, for example, Ford UK is
a differrent manufacturer to Ford US. Hence the same userform is
initialised to show countries for the user to select, This is what I
meant by the second instance of the userform. So the user now sees two
instances of the same userform, the first showing service provider
names and the second showing countries for them to select from.

Each userform allows the user to right mouse click and make a
selection. Within the service provider userform this will produce
options to rename, add or delete a service provider. Right mouse-
clicking within the countries userform will allow the user to
rename,add or delete countries.

By a lot of smoke and mirrors this is all working but not as elegantly
as I would like. If I should need to go to a 3rd level of userform in
the future then it's going to be even more difficult.

The major issue remains that, because I have to keep the CommandBar
popup menu OnAction target module as a general module, I do not
understand how to have that general module know which userform it's
talking to - if the user selects "delete", for example, am I deleting
a service provider or a country?

If the OnAction module was within the same Class module as the
userform, then this would take care of itself, bu it's obviously not.

Is this explanation any clearer?
 
N

Neil

Again you say -

"So the user now sees two instances of the same userform"

I take it you mean the user sees two similar looking userforms, right?

Not to worry, I'm now starting to get the idea. There are several approaches
but the simplest (as in for me to suggest without knowing exactly what
you've got) is to assign a temporary object variable in a normal module with
a reference to the form, something like this

' in the form
Sub DoPopup
Set gObjFrm = Me
' code to create the popup
myPopupBar.ShowPopup
myPopupBar.Delete
Set gObjFrm = Nothing
end sub

' maybe you might want this
Public Sub MyProc() ' don't forget the public
' do stuff
End Sub

' in a normal module
Public gObjFrm as Object

Sub Macro1()
' directly work on a control
gObjFrm.SomeControl.SomeProperty = NewValue
'or maybe call a routine in the form
Call gObjFrm.MyProc

Set gObjFrm = Nothing ' or do that back in the form
End Sub

As I say, there may well be better approaches with more control and/or more
elegant ways, but something like the above should work.

Regards,
Peter T







I apologise if my description is not clear - I'll try again:

There is one "user selection" userform that is initialised depending
on what attribute the user is working with. These can include, for
example, service providers, colours, countries, locations - anything
that can be represented as a hierarchical tree.

If the user is working with service providers, these are displayed in
what I referred to as the first instance of the userform. Service
providers have a second attribute of country, for example, Ford UK is
a differrent manufacturer to Ford US. Hence the same userform is
initialised to show countries for the user to select,  This is what I
meant by the second instance of the userform. So the user now sees two
instances of the same userform, the first showing service provider
names and the second showing countries for them to select from.

Each userform allows the user to right mouse click and make a
selection. Within the service provider userform this will produce
options to rename, add or delete a service provider.  Right mouse-
clicking within the countries userform will allow the user to
rename,add or delete countries.

By a lot of smoke and mirrors this is all working but not as elegantly
as I would like. If I should need to go to a 3rd level of userform in
the future then it's going to be even more difficult.

The major issue remains that, because I have to keep the CommandBar
popup menu OnAction target module as a general module, I do not
understand how to have that general module know which userform it's
talking to - if the user selects "delete", for example, am I deleting
a service provider or a country?

If the OnAction module was within the same Class module as the
userform, then this would take care of itself, bu it's obviously not.

Is this explanation any clearer?

Hi again Peter - thanks for taking the time to reply.

Just to be clear, there is only one user form. I do something like
this:

set oUF1 = New TreeViewForm
- initialise to read and display service providers

set oUF2 = New TreeViewForm
- initialise to read and display countries

On right mouse click from within oUF1 the user will get the form oUF2
displayed to display selectable countries. From within oUF2 they can
also right mouse click to, for example, add a new country.

I've done it this way because, apart from the specific content of
service providers, countries, colours, or whatever, the same basic
logic and processing applies to them all, namely select, add, rename
and delete.

I think I understand your approach, will give it a try and post back
tomorrow with the results.

Many thanks
 
P

Peter T

My apologies, you can indeed have two instance of the same form. Anyway, the
approach I suggested will hopefully work for you.

Regards,
Peter T

Again you say -

"So the user now sees two instances of the same userform"

I take it you mean the user sees two similar looking userforms, right?

Not to worry, I'm now starting to get the idea. There are several
approaches
but the simplest (as in for me to suggest without knowing exactly what
you've got) is to assign a temporary object variable in a normal module
with
a reference to the form, something like this

' in the form
Sub DoPopup
Set gObjFrm = Me
' code to create the popup
myPopupBar.ShowPopup
myPopupBar.Delete
Set gObjFrm = Nothing
end sub

' maybe you might want this
Public Sub MyProc() ' don't forget the public
' do stuff
End Sub

' in a normal module
Public gObjFrm as Object

Sub Macro1()
' directly work on a control
gObjFrm.SomeControl.SomeProperty = NewValue
'or maybe call a routine in the form
Call gObjFrm.MyProc

Set gObjFrm = Nothing ' or do that back in the form
End Sub

As I say, there may well be better approaches with more control and/or
more
elegant ways, but something like the above should work.

Regards,
Peter T







I apologise if my description is not clear - I'll try again:

There is one "user selection" userform that is initialised depending
on what attribute the user is working with. These can include, for
example, service providers, colours, countries, locations - anything
that can be represented as a hierarchical tree.

If the user is working with service providers, these are displayed in
what I referred to as the first instance of the userform. Service
providers have a second attribute of country, for example, Ford UK is
a differrent manufacturer to Ford US. Hence the same userform is
initialised to show countries for the user to select, This is what I
meant by the second instance of the userform. So the user now sees two
instances of the same userform, the first showing service provider
names and the second showing countries for them to select from.

Each userform allows the user to right mouse click and make a
selection. Within the service provider userform this will produce
options to rename, add or delete a service provider. Right mouse-
clicking within the countries userform will allow the user to
rename,add or delete countries.

By a lot of smoke and mirrors this is all working but not as elegantly
as I would like. If I should need to go to a 3rd level of userform in
the future then it's going to be even more difficult.

The major issue remains that, because I have to keep the CommandBar
popup menu OnAction target module as a general module, I do not
understand how to have that general module know which userform it's
talking to - if the user selects "delete", for example, am I deleting
a service provider or a country?

If the OnAction module was within the same Class module as the
userform, then this would take care of itself, bu it's obviously not.

Is this explanation any clearer?

Hi again Peter - thanks for taking the time to reply.

Just to be clear, there is only one user form. I do something like
this:

set oUF1 = New TreeViewForm
- initialise to read and display service providers

set oUF2 = New TreeViewForm
- initialise to read and display countries

On right mouse click from within oUF1 the user will get the form oUF2
displayed to display selectable countries. From within oUF2 they can
also right mouse click to, for example, add a new country.

I've done it this way because, apart from the specific content of
service providers, countries, colours, or whatever, the same basic
logic and processing applies to them all, namely select, add, rename
and delete.

I think I understand your approach, will give it a try and post back
tomorrow with the results.

Many thanks
 

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