Display a TextBox or Non-modal Message Box

Hi all. What I'm trying to do is put up a user form with a text box while a process is running. I don't need a progress bar, as the process is not that long. I have created a userform that includes a textbox, but only the userform comes up when I ".show" it. Why won't the text box portion of the userform show?

Alternatively, is it possible to put up a "non-modal" system message box? Can I apply some sort of counter to that to only leave it up a certain amount of time? The standard message box (MsgBox() ) requires user interaction, and the application will not proceed until that user action.

Any help would be appreciated.

[828 byte] By [sg549] at [2008-1-8]
# 1

Hi

The usual way is to do frm.Repaint after you have updated it.

Regards

Peter Mo.

PeterMo. at 2007-10-2 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 2

Hey,

In the Properties Window for the TextBox object check that Visible is set to True,

and/or you can also use code in the Intialize event of the form.

Private Sub UserForm_Initialize()

TextBox1.Visible = True

End Sub

There is NO message box in VBA for Excel that you can show to the user while a procedure runs, as fare as I now…

But there is a way around this. Create your own message box and in the in the Properties Window for the UserForm set the ShowModal to False. In the Activate event insert the code below to show your own MsgBox for 5 seconds.

Private Sub UserForm_Activate()

Application.Wait Now + TimeValue("00:00:05")

Unload Me

End Sub

Best Regards

Cathrine

MyLady at 2007-10-2 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 3

Catherine:

I have tried what you suggested, with no luck. I have tried many different things that I've found in various places, but somehow, I can not get the text box or a label to come up when the userform appears. I can't figure it out.

The modal setting is set to false, the form is set to visible=true in the properties...I don't know what else to do. How can the userform come up, but not what I've placed inside it?

Thanks again for your help.

sg549 at 2007-10-2 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 4
Hi,

Can you post the code in the userform and any code you use to display the userform.

As the others have said there should really be no reason why the control is not displayed is you are doing what you say.

AndyPope at 2007-10-2 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 5

Well, I have consulted a C# programmer friend of mine, and he has provided the answer. There is no need to "initialize" the form, or even to write event handling code. You must create an instance of the form, then all attributes can be set programmatically, including the text.

For example, I create a new user form called UserForm2, and add a label (Label1). I state in the Sub: Dim uf2 as New UserForm2, so that any time I call (or show) uf2, an instance is created, and I can do what I want with it.

uf2.Label1 = "Text goes here"

uf2.Show xlModal = False

Of course, other attributes can be set programmatically, or you can set them in the properties box of the UserForm/Label1. You guys may want to try this, as it is much easier than the other things I've tried, AND it works!

Thanks again.

sg549 at 2007-10-2 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 6

Glad you solveed your problem. The approach your friend recommended is indeed a good approach to take, although I think using the Initialize event is a valid place to included encapsulated code.

But this does not really address the problem you had. There is no reason why you can not set the properties at design time and simply show the userform, I would suggest that this is how the majority of people approach userform coding.
So unless the workbook was corrupt you must have been doing something else. Either by code or manually and you just didn't understand the impact it could have.

AndyPope at 2007-10-2 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...