Consulting

Results 1 to 15 of 15

Thread: active box on a userform

  1. #1

    active box on a userform

    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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    How ill this macro be triggered? In other words, do you want it to happen when the control is entered, or from a button?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    hi there

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

    does this make sense?

  4. #4
    and perhaps by a button as while depending on the code

    is there much differemce in the code?

    may as well learn both options

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    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?

  7. #7
    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

  8. #8
    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

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  10. #10
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    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

  11. #11
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    northernstar

    What is the purpose of this?

  12. #12
    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

  13. #13
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    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.

  14. #14
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I think that is what myself and mikerickson have been saying for the past two days. Welcome aboard!
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  15. #15

    active text/combobox

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •