PDA

View Full Version : active box on a userform



northernstar
10-30-2007, 04:35 PM
hi all...long time...no posts from me

but here is a litte problem i have at the moment

i have userform with textboxes & comboboxes and i would like to be able to run some code depending on which box is active

is this possible?

many thanks in advance

Bob Phillips
10-30-2007, 04:52 PM
How ill this macro be triggered? In other words, do you want it to happen when the control is entered, or from a button?

northernstar
10-30-2007, 05:00 PM
hi there

i would like the code to be triggered by either the change or after update event

does this make sense?

northernstar
10-30-2007, 05:01 PM
and perhaps by a button as while depending on the code

is there much differemce in the code?

may as well learn both options

Bob Phillips
10-30-2007, 05:11 PM
The problem with a button is that as soon as you click it, it becomes the activecontrol.

If it is triggered by a Change or AFterUpdate, you know which one is active as you are in that control's event code.

mikerickson
10-30-2007, 05:15 PM
If you are using event code to trigger the routine, the control that triggers the event will have the focus when the routine starts. It sounds like the .ActiveControl property of the Userform might be useful to you, but since your every event routine "knows" which control is active (i.e. has the focus) when it starts I'm a little confused about what you want.

Or by "active" do you mean .Enabled=True?

northernstar
10-30-2007, 05:18 PM
now i have confused myself, it is getting late and im quite tired, will have another look at my problem and let you know

and perhpas upload a sample file

thanks

northernstar
10-30-2007, 11:57 PM
the problem i have is that when the user enters a value into a textbox or selects an option from a dropdown and they havent tabbed to the next box then i would like the code to be triggered depending on the value in that box

i am going to have a play with .ActiveControl

and i will let you know how i get along

thanks

Bob Phillips
10-31-2007, 01:03 AM
I don't think so because ACtiveControl will be that Listbox or that TextBox, whereas you are suggesting that you just what the control's value.

mikerickson
10-31-2007, 07:41 AM
What you are describing sounds like a _Change event, perhaps like

Private Sub TextBox1_Change()
With Me.TextBox1
Select Case True
Case .Value = "one"
Rem some code
Case Val(.Value) < 3
Rem some other code
End Select
End With
End Sub

Norie
10-31-2007, 08:06 AM
northernstar

What is the purpose of this?

northernstar
10-31-2007, 11:41 AM
its a technical spreadsheet and form, which we enter pressure values into the form calculations are done and a end would like it to check to see if the current selected box is empty

hope this helps

Norie
10-31-2007, 11:47 AM
If that's the case I don't see why you need to work with the active control.

There are at least 2 ways to check that data has been entered.

1 Use one of the events of the textbox eg Exit to see if data has been entered and prevent the user from moving on.

2 Go through the controls before you do the calculations.

Bob Phillips
10-31-2007, 12:07 PM
I think that is what myself and mikerickson have been saying for the past two days. Welcome aboard!

northernstar
10-31-2007, 04:06 PM
thanks everyone for their inpuit on this problem

still not sure if the answer i need is almost your replies but i will try them and let you know how i get on

thanks again