Consulting

Results 1 to 18 of 18

Thread: Userform management

  1. #1
    VBAX Contributor
    Joined
    Aug 2006
    Posts
    120
    Location

    Userform management

    Hi, Im having some problems with hiddin the userform when asking for info. For example I tried to set a userform with a button. when it is actioned, the userform must hide, ask for some variables through Inpubox commands and then re-appear. I used .hide, action the inputboxes and then .show but when the .show sentence is reached, the proceeding code is never reached until the userform is terminated. I have also tried with the visible property but I keep gettin some errors. Is there an easy way to "disappear" a userform without having so much trouble with the code? thanks

  2. #2
    VBAX Contributor
    Joined
    Aug 2006
    Posts
    120
    Location

    Example

    Example

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by makako
    Example
    Works fine for me.

  4. #4
    VBAX Contributor
    Joined
    Aug 2006
    Posts
    120
    Location
    It pops a message (in the visible button) that says the function or the interface is marked as restricted or the function uses an automatization non admitted in VBA, and in the show/hide it never reaches the code .backcolor until I terminate the userform. It is obvious I could move it before the show sentence but this is just an example of a much complicated addin Im working on and on various actions i have to hide and show the userform.
    (I tried granting access to VBA proyects but the resut is the same)

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

    Why are you using inputboxes and a userform?

    Surely that defeats the purpose of the userform?

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I see how you are getting that now.

    You have this code

    [vba]

    UserForm1.Visible = False
    [/vba]

    You know that is not how you hide the form, you use

    [vba]

    Userform1.Hide
    [/vba]

    which is the correct way.

  7. #7
    VBAX Contributor
    Joined
    Aug 2006
    Posts
    120
    Location
    I use the inputbox to add new data and the textboxes for modifying. Plus I also run some cheks with the inputboxes. In my example I set two buttons, one with visible and other with hide/show. I get the mentioned error with the .visible way but when using the hide and show way it nerver reaches (as I mentioned before) the following code

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    This coide

    [vba]

    Private Sub CommandButton2_Click()
    UserForm1.Hide
    Var = InputBox("Code")
    Var = InputBox("Code")
    UserForm1.Show
    CommandButton1.BackColor = vbBlue
    End Sub
    [/vba]

    works fine for me

  9. #9
    VBAX Contributor
    Joined
    Aug 2006
    Posts
    120
    Location
    Maybe Ive not been clear enough. Do you get your button turn blue?, cause when it reaches userform.show it never reaches the turn blue until I terminate the userform. Thats not the idea. Another example, If I want to send a msgbox without the userform to be on screen, can I hide it and then make it visible and hace the code continue without waiting to be terminated?

  10. #10
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    I'll repeat what I said.
    Quote Originally Posted by Norie
    makako

    Why are you using inputboxes and a userform?

    Surely that defeats the purpose of the userform?

  11. #11
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    [VBA]
    Private Sub CommandButton2_Click()
    UserForm1.Hide
    Var = InputBox("Code")
    Var = InputBox("Code")
    CommandButton2.BackColor = vbBlue
    UserForm1.Show
    End Sub
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  12. #12
    VBAX Contributor
    Joined
    Aug 2006
    Posts
    120
    Location
    Norie, its a dummy of a much more complex userform, Forget about the inputbox, try a message box when unacceptable data is entered and I dont want the userform to be seen when the msgbox is shown. If i use the show/hide instance the following code will never be reached after showing the userform. And Lucas,
    ... userform. It is obvious I could move it before the show sentence but this is just an example of a much complicated addin Im working on and on various actions i have to hide and show the userform. ...

    Let me change the thread: Is there anyway I can use the visible property instead?

  13. #13
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Quote Originally Posted by makako
    ...
    Let me change the thread: Is there anyway I can use the visible property instead?
    No, click on the userform and look in the properties window. You'll see 'Visible' is not a userform property (that's why you were getting an error msg)
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  14. #14
    VBAX Contributor
    Joined
    Aug 2006
    Posts
    120
    Location
    yes, but when it write userform1. the list allows me the visible property. thanks anyway.

  15. #15
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    If you're referring to the intellisense list, the visible there is only intended to be used as a boolean test e.g. [VBA]If UserForm1.Visible Then MsgBox "Userform1 is Visible"[/VBA]
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  16. #16
    VBAX Contributor
    Joined
    Aug 2006
    Posts
    120
    Location
    ok, thanks

  17. #17
    You could of course just move the form out of sight:
    [VBA]Private Sub CommandButton1_Click()
    Dim dTop As Double
    dTop = Me.Top
    Me.Top = 2000
    MsgBox "Form is out of the way"
    Me.Top = dTop
    End Sub
    [/VBA]
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  18. #18
    VBAX Contributor
    Joined
    Aug 2006
    Posts
    120
    Location
    thanks, more useful of all replies until now

Posting Permissions

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