PDA

View Full Version : Blank Userform?



Odyrus
09-27-2011, 11:16 AM
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!
:beerchug:

Bob Phillips
09-27-2011, 11:32 AM
You need to show the form and run your macro from within there, close the form when the macro ends.

Odyrus
09-27-2011, 11:44 AM
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?

Bob Phillips
09-27-2011, 11:50 AM
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.

Odyrus
09-27-2011, 11:55 AM
Thanks for the direction! I'll play around with it!

Cheers!
:beerchug:

Aflatoon
09-28-2011, 04:53 AM
You can also show the form modelessly and then repaint it immediately before your remaining code is called.

Odyrus
09-28-2011, 04:59 AM
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. :)

Aflatoon
09-28-2011, 05:03 AM
Did you repaint it after showing? Or use DoEvents?

Odyrus
09-28-2011, 05:05 AM
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.

Aflatoon
09-28-2011, 06:17 AM
Either of these should work:

Dim myForm as userform1
set myForm = New Userform1
myform.show false
myform.repaint
' the rest of your code would go here

or:
Dim myForm as userform1
set myForm = New Userform1
myform.show false
DoEvents
' the rest of your code would go here

Odyrus
09-28-2011, 06:30 AM
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!
:beerchug:

Aflatoon
09-28-2011, 06:33 AM
At the end of the routine, it would just be:
Set myForm = Nothing

Odyrus
09-28-2011, 06:39 AM
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?

Aflatoon
09-28-2011, 12:26 PM
My apologies - glaring omission there. It should be:

unload myForm
Set myForm = Nothing

Odyrus
09-28-2011, 12:57 PM
Works like a charm!

Cheers!

Odyrus
10-05-2011, 12:32 PM
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 Unload myForm
Any thoughts on this mate?

Many thanks!

Odyrus
10-05-2011, 01:24 PM
I think I fixed it, not sure if its proper though...

Here's my solution:

On Error Resume Next
Unload myForm

mikerickson
10-05-2011, 05:38 PM
You could name the userform explicitly rather than refering to a variable. Unload Userform1 or you could assign the variable myForm to Userform1 at the beginning of the routine, before the user has an opportunity to cancel.