Finding name of subroutine or button (probably simple)

G

gary167

I have a userform setup with a multipage control. I have various
textboxes that need to be filled out for various information. I have
also included a option button (copyhpm2) which will allow me to do a
quick subroutine and then allow me to update the text of a box.

My issue is that I would like to be able to find out which button has
been pushed. (I know I could hardcode this with a variable, but there
are a lot of these).

As another footnote, how can I determine the next, or previous, text
box in the tab order programatically.

Thanks,

Gary
 
J

Jezebel

the active control is, oddly enough, Me.ActiveControl

Tabindexes are harder to work with, because there are separate sequences for
each container (ie the form, each page of the multipage, each frame, etc).
So to determine the next/previous control, you need to determine the
control's container then iterate the controls in that container; and as far
as I know VBA (unlike VB) doesn't provide any easy way to do this. Probably
simpler to set up an array or collection in the form's Initialize event;
then to determine the next/previous, look up the control in the list and
check its neighbours.
 
G

Gary

Thanks for the response. I've tried ?me.activecontrol.name and it
returns "multipage1".
What I'm trying to do is determine which option button (or
commandbutton) was pressed. Based on its name, I can deduce what the
next/previous textboxes are.

I went ahead and hardcoded the info into all 75 buttons, but now the
hard-headed side of me just won't let go! There's got to be a way
programatically.

Thanks,

Gary
 
J

Jezebel

You're right. You have to drill down:

MultiPage1.Pages(MultiPage1.Value).ActiveControl.Name
 
G

Gary

THANK YOU !!!!!

I didn't know you could do that. Sure is a whole bunch cleaner than
setting up a batch of public variables. Now I can just pass along the
name and the code will do the work for me!

Thanks again,
Gary
 

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