Consulting

Results 1 to 18 of 18

Thread: Blank Userform?

  1. #1
    VBAX Regular
    Joined
    May 2011
    Posts
    63
    Location

    Blank Userform?

    Good day!

    I'm attempting to have a userform display a message while my macro runs however, the userform is showing up as blank when I run the macro. I'm a bit baffled at this? Appreciate any comments or help!

    Cheers!
    tóg(a'í) go réidh é!

    Cheers!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You need to show the form and run your macro from within there, close the form when the macro ends.
    ____________________________________________
    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
    VBAX Regular
    Joined
    May 2011
    Posts
    63
    Location
    Thanks for the prompt reply!

    I think I understand what you are getting at.

    So am I basically copying the code from my module and putting it into the userform? Will this work still if I'm calling the macro from a button and the user needs to input data?
    tóg(a'í) go réidh é!

    Cheers!

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    NO, you can leave the code in your module, but just call the sub from the form, say in the Userform_Activate event.

    If you have a button to launch it, the button would launch another macro to show the userform.
    ____________________________________________
    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

  5. #5
    VBAX Regular
    Joined
    May 2011
    Posts
    63
    Location
    Thanks for the direction! I'll play around with it!

    Cheers!
    tóg(a'í) go réidh é!

    Cheers!

  6. #6
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    You can also show the form modelessly and then repaint it immediately before your remaining code is called.
    Be as you wish to seem

  7. #7
    VBAX Regular
    Joined
    May 2011
    Posts
    63
    Location
    Thanks for the suggestion Aflatoon.

    I had the mode turned to false and was still have issues with the form showing blank. I found some additional bits of code out on the web but was having trouble getting them to work.

    I think that in the end, my WB will end up being a little less fancy than i was planning as I'm still encountering some issues.
    tóg(a'í) go réidh é!

    Cheers!

  8. #8
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Did you repaint it after showing? Or use DoEvents?
    Be as you wish to seem

  9. #9
    VBAX Regular
    Joined
    May 2011
    Posts
    63
    Location
    I tried inserting the form at the beginning of the macro I wanted it to pop during and unsuccessfully tried repainting it. Didn't work for me...

    I did not use a DoEvent.
    tóg(a'í) go réidh é!

    Cheers!

  10. #10
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Either of these should work:
    [vba]
    Dim myForm as userform1
    set myForm = New Userform1
    myform.show false
    myform.repaint
    ' the rest of your code would go here
    [/vba]
    or:[vba]
    Dim myForm as userform1
    set myForm = New Userform1
    myform.show false
    DoEvents
    ' the rest of your code would go here
    [/vba]
    Be as you wish to seem

  11. #11
    VBAX Regular
    Joined
    May 2011
    Posts
    63
    Location
    Aflatoon,

    Both of your solutions work perfectly, thank you mate!

    I can't get my the form to disappear after the macro runs. I tried unloading the form but it's not working. Any thoughts?

    Cheers!
    tóg(a'í) go réidh é!

    Cheers!

  12. #12
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    At the end of the routine, it would just be:
    [vba]Set myForm = Nothing[/vba]
    Be as you wish to seem

  13. #13
    VBAX Regular
    Joined
    May 2011
    Posts
    63
    Location
    Hmmm.... using that bit of code doesn't seem to be having any affect. The form is stubbornly not disappearing.

    I'm using the DoEvents syntax you provided. I'm uncertain if that would make a difference?
    tóg(a'í) go réidh é!

    Cheers!

  14. #14
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    My apologies - glaring omission there. It should be:
    [vba]
    unload myForm
    Set myForm = Nothing[/vba]
    Be as you wish to seem

  15. #15
    VBAX Regular
    Joined
    May 2011
    Posts
    63
    Location
    Works like a charm!

    Cheers!
    tóg(a'í) go réidh é!

    Cheers!

  16. #16
    VBAX Regular
    Joined
    May 2011
    Posts
    63
    Location
    Good day Alfatoon,

    I seem to have encountered one more error with the userform code you've provided.

    The userform displays while a macro runs and works great. The macro is prompted from a user selecting a button. When the user cancels out of the button to prevent the macro from running I get an "Object variable or With block not set". When I debug its pointing me to the code [vba]Unload myForm[/vba]
    Any thoughts on this mate?

    Many thanks!
    tóg(a'í) go réidh é!

    Cheers!

  17. #17
    VBAX Regular
    Joined
    May 2011
    Posts
    63
    Location
    I think I fixed it, not sure if its proper though...

    Here's my solution:
    [VBA]
    On Error Resume Next
    Unload myForm[/VBA]
    tóg(a'í) go réidh é!

    Cheers!

  18. #18
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    You could name the userform explicitly rather than refering to a variable. [vba]Unload Userform1[/vba] or you could assign the variable myForm to Userform1 at the beginning of the routine, before the user has an opportunity to cancel.

Posting Permissions

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