Userform leaving a trail

B

Brett

I had some trouble with moving a userform around and using screenupdating =
false because the userform left a trail behind. So, I change the code to:
UF0_QCP.Hide: Sleep 200

where UF0_QCP is the userform. Now, it doesn't leave a trail, but the UF
stays in the old spot with a completely white background whilst
simultaneously displaying properly in the new spot (better, but still not
professional).

I'm sure that someone out there has a tachnique that they's love to share
with me (please). Regards, Brett
 
R

RB Smissaert

Simplest is to set Application.ScreenUpdating = True and only set it to
False when it really is needed.
You could otherwise use the Windows API to solve this, but that will get a
bit complex.

The other option is to show the form modeless:

Load UserForm1
UserForm1.Show vbModeless

but that may not suit your particular situation.

RBS
 
M

Mike H

Hi,

You'll encounter this with screen updating set to false. Set updatting to
true.

Mike
 
B

Brett

Thanks for your response. There's no chance that I can load it modeless on a
few different fronts, and in enough sections it jumps around a few books and
sheets so scr.upd is pretty much essential so...............how complex is
complex using the API? No time like the present (eh?). Brett.
 
B

Brett

Hi again Mike, no chance I'm afraid - it's a case of stop it or you'll go
blind. I'm interested to see what RBS has to say about using the API. Brett
 
H

Harald Staff

Put

DoEvents

in your code so that it happens at least every three seconds. It means "take
a short break and listen to the operating system". Allowing windows to
reposition, your orders to interrupt the running code, occational emails to
be delivered, ... Yes it slows down the code, but makes it far less annoying
as a user experience.

HTH. Best wishes Harald
 
R

RB Smissaert

Here is one way without any API.
It is not perfect, but is a starting point.

In the UserForm module:
---------------------------

Option Explicit
Private lTop As Long
Private lLeft As Long

Private Sub CommandButton1_Click()
RunLoop
End Sub

Private Sub UserForm_Layout()

If CLng(UserForm1.Top) <> lTop Or _
CLng(UserForm1.Left) <> lLeft Then
lTop = UserForm1.Top
lLeft = UserForm1.Left
Application.ScreenUpdating = True
Application.ScreenUpdating = False
End If

End Sub

In a normal module:
-----------------------

Option Explicit

Sub StartForm()

Application.ScreenUpdating = False

Load UserForm1
UserForm1.Show vbModal

End Sub

Sub RunLoop()

Dim i As Long

For i = 0 To 100000000
If i Mod 1000000 = 0 Then
DoEvents
End If
Next i

MsgBox "finished loop"

End Sub



RBS
 
B

Brett

Hi Harald, thank you for that. A quick question (with time zones in mind -
I'm in Oz) before I try some fooling around with that: Should the DoEvents go
just before or just after I'm hiding the UF? How do I get DoEvents to fire
every 3 (or whatever) seconds?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top