ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   UserForm - Last Active control (https://www.excelbanter.com/excel-programming/359579-userform-last-active-control.html)

MattShoreson[_87_]

UserForm - Last Active control
 

The situation...

I have a form with 4 combos, one parent and three childs.
I have a few command buttons.

When I select the parent the child combo are activated, then when one
of the childs is changed, the contents of the other two child boxes are
poulated with related data.

If I want to delete the data, i.e. click the delete button, how can I
find out which was the last child box changed?

I've thought about using a public variable to store a value based on
the last box changed, (1 for combo1 etc) but is there any other way of
doing this cleanly?

ta,
Matt.


--
MattShoreson
------------------------------------------------------------------------
MattShoreson's Profile: http://www.excelforum.com/member.php...fo&userid=3472
View this thread: http://www.excelforum.com/showthread...hreadid=535458


Bob Phillips[_6_]

UserForm - Last Active control
 
Not really. There is ACtiveControl, but the Delete button will get that.
Variable seems the only way.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"MattShoreson"
wrote in message
news:MattShoreson.26rn7b_1145877602.4088@excelforu m-nospam.com...

The situation...

I have a form with 4 combos, one parent and three childs.
I have a few command buttons.

When I select the parent the child combo are activated, then when one
of the childs is changed, the contents of the other two child boxes are
poulated with related data.

If I want to delete the data, i.e. click the delete button, how can I
find out which was the last child box changed?

I've thought about using a public variable to store a value based on
the last box changed, (1 for combo1 etc) but is there any other way of
doing this cleanly?

ta,
Matt.


--
MattShoreson
------------------------------------------------------------------------
MattShoreson's Profile:

http://www.excelforum.com/member.php...fo&userid=3472
View this thread: http://www.excelforum.com/showthread...hreadid=535458




[email protected]

UserForm - Last Active control
 
Hi
A public variable (call it ChildState) in the form code window acts as
an object for the form. You could set a value for this variable in the
combo1_change event for the combobox

private sub combo1_change()
ChildState = 1
end sub

do the same for the other two boxes.
Then myForm.ChildState has value 1, 2 or 3.
Not tested, so I don't know if this persists between calls of the form.
Doubtful.

regards
Paul


Dave Peterson

UserForm - Last Active control
 
Maybe the buttons could have .takefocusonclick set to false in the
initialization routine or even manually during design?



Bob Phillips wrote:

Not really. There is ACtiveControl, but the Delete button will get that.
Variable seems the only way.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"MattShoreson"
wrote in message
news:MattShoreson.26rn7b_1145877602.4088@excelforu m-nospam.com...

The situation...

I have a form with 4 combos, one parent and three childs.
I have a few command buttons.

When I select the parent the child combo are activated, then when one
of the childs is changed, the contents of the other two child boxes are
poulated with related data.

If I want to delete the data, i.e. click the delete button, how can I
find out which was the last child box changed?

I've thought about using a public variable to store a value based on
the last box changed, (1 for combo1 etc) but is there any other way of
doing this cleanly?

ta,
Matt.


--
MattShoreson
------------------------------------------------------------------------
MattShoreson's Profile:

http://www.excelforum.com/member.php...fo&userid=3472
View this thread: http://www.excelforum.com/showthread...hreadid=535458


--

Dave Peterson

MattShoreson[_88_]

UserForm - Last Active control
 

Cheers for the response on this one guys.

In addition, how would I go about getting the finding out which control
was changed by the user?

e.g. if parent changed, then child1 changed, child2 auto-populated,
child3 auto-populated.

I'd like to find out that child1 is the lastbox user interacted with.

ta,
Matt.


--
MattShoreson
------------------------------------------------------------------------
MattShoreson's Profile: http://www.excelforum.com/member.php...fo&userid=3472
View this thread: http://www.excelforum.com/showthread...hreadid=535458


Bob Phillips[_6_]

UserForm - Last Active control
 
I think that only your code will know that will it not? Or am I missing
something?

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"MattShoreson"
wrote in message
news:MattShoreson.26rys0_1145892603.8298@excelforu m-nospam.com...

Cheers for the response on this one guys.

In addition, how would I go about getting the finding out which control
was changed by the user?

e.g. if parent changed, then child1 changed, child2 auto-populated,
child3 auto-populated.

I'd like to find out that child1 is the lastbox user interacted with.

ta,
Matt.


--
MattShoreson
------------------------------------------------------------------------
MattShoreson's Profile:

http://www.excelforum.com/member.php...fo&userid=3472
View this thread: http://www.excelforum.com/showthread...hreadid=535458




MattShoreson[_91_]

UserForm - Last Active control
 

Not too sure what you're getting at Bob. It's not necessarily the case
that its child1 that altered, it may be child2 or child3.

Just wondered whether there was a neat way of doing all of this
processing as I already have a public variable to prevent recursive
attempts of combo change event.

Didn't really want to complicate further with another public var
containing lastbox clicked as well along with the associated evaluation
of additional var.

cheers though.
Matt.


--
MattShoreson
------------------------------------------------------------------------
MattShoreson's Profile: http://www.excelforum.com/member.php...fo&userid=3472
View this thread: http://www.excelforum.com/showthread...hreadid=535458


Bob Phillips[_6_]

UserForm - Last Active control
 
Matt,

What I mean is that the decision as to whether child1 or child2 or child3 is
altered would contained within the logic in your code. If you are only
referring to the last box clicked, then doesn't ACtivecontrol get you that,
combined with Dave's suggestion of not giving the commandbutton focus?

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"MattShoreson"
wrote in message
...

Not too sure what you're getting at Bob. It's not necessarily the case
that its child1 that altered, it may be child2 or child3.

Just wondered whether there was a neat way of doing all of this
processing as I already have a public variable to prevent recursive
attempts of combo change event.

Didn't really want to complicate further with another public var
containing lastbox clicked as well along with the associated evaluation
of additional var.

cheers though.
Matt.


--
MattShoreson
------------------------------------------------------------------------
MattShoreson's Profile:

http://www.excelforum.com/member.php...fo&userid=3472
View this thread: http://www.excelforum.com/showthread...hreadid=535458




MattShoreson[_92_]

UserForm - Last Active control
 

my apologies Bob, I didn't clarify well enough.

Process would be..
Parent box.
Any of the three children boxes.
Then a command button

I believe active control would give me the command button rather tha
the box

--
MattShoreso
-----------------------------------------------------------------------
MattShoreson's Profile: http://www.excelforum.com/member.php...nfo&userid=347
View this thread: http://www.excelforum.com/showthread.php?threadid=53545


MattShoreson[_93_]

UserForm - Last Active control
 

sorry bob, light bulb clicked - was being stupid for a minute.
cant see the wood for the trees etc, etc,etc

--
MattShoreso
-----------------------------------------------------------------------
MattShoreson's Profile: http://www.excelforum.com/member.php...nfo&userid=347
View this thread: http://www.excelforum.com/showthread.php?threadid=53545


Bob Phillips[_6_]

UserForm - Last Active control
 
LOL. Hope we have success now then.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"MattShoreson"
wrote in message
news:MattShoreson.26tokz_1145972707.3953@excelforu m-nospam.com...

sorry bob, light bulb clicked - was being stupid for a minute.
cant see the wood for the trees etc, etc,etc.


--
MattShoreson
------------------------------------------------------------------------
MattShoreson's Profile:

http://www.excelforum.com/member.php...fo&userid=3472
View this thread: http://www.excelforum.com/showthread...hreadid=535458





All times are GMT +1. The time now is 10:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com