UserForm Disappears occasionally or is partially displayed

User avatar
Don Wells
5StarLounger
Posts: 689
Joined: 27 Jan 2010, 16:45
Location: Ottawa, Ontario, Canada

UserForm Disappears occasionally or is partially displayed

Post by Don Wells »

Still Running Excel 2007 on Windows 7

I have a program which loads a UserForm (attached image) with the following code:

Code: Select all

Private Sub Workbook_Open()
  Call MultiPass.Re_size
     UserForm1.LabelProgress.Width = 0
    UserForm1.Show
    DoEvents
End Sub
I have noticed that on occasion the UerForm disappears/reappears with or without the caption and Label1 while executing the following For-Next snippet. Being suspicious that the form was being missed on a ScreenUpdating command, I have liberally populated the code with "DoEvents" commands; but still get caught occasionally.

Code: Select all

  For delay = Prep_Time To 0 Step -1
    Range("A1") = delay
    DoEvents
    Application.ScreenUpdating = True
    DoEvents
    ctr = ctr + 1
    Application.Wait TimeValue("0:00:" & Format(ctr, "00")) + start
  Next delay
I am attaching the latest version of the file for those who wish to play with it. Any guidance will be greatly appreciated.
You do not have the required permissions to view the files attached to this post.
Last edited by Don Wells on 21 Apr 2020, 20:09, edited 1 time in total.
Regards
Don

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: UserForm Disappears occasionally or is partially display

Post by HansV »

It's difficult to understand what the workbook does (or is supposed to do), but: you have two blocks With UserForm1 ... End With. Does it help if you insert a line

Code: Select all

        .Repaint
just above End With in both blocks?
Best wishes,
Hans

User avatar
Don Wells
5StarLounger
Posts: 689
Joined: 27 Jan 2010, 16:45
Location: Ottawa, Ontario, Canada

Re: UserForm Disappears occasionally or is partially display

Post by Don Wells »

Thank you for your guidance Hans. I have incorporated your recommendation and added a missing line in the same procedure that you commented on; just in case you wanted to run the code. I have also replaced the file in my original post.

As an explanation of the workbook. It provides timing for the user in performing a series of exercises; either reprogrammed or selected by the user. there are different inputs for each exercise: name; Stress time; Rest time; Preparation/Set-up time; the number of repetitions; and the number of times each exercise is cycled through the list. The UserForm provides a graphical display of progress through each stress and rest time.
Last edited by Don Wells on 21 Apr 2020, 20:32, edited 1 time in total.
Regards
Don

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: UserForm Disappears occasionally or is partially display

Post by HansV »

And did it help?
Best wishes,
Hans

User avatar
Don Wells
5StarLounger
Posts: 689
Joined: 27 Jan 2010, 16:45
Location: Ottawa, Ontario, Canada

Re: UserForm Disappears occasionally or is partially display

Post by Don Wells »

That's the distressing thing about intermittent faults. You are seldom uncertain. But, it didn't appear to harm.
Regards
Don

User avatar
Don Wells
5StarLounger
Posts: 689
Joined: 27 Jan 2010, 16:45
Location: Ottawa, Ontario, Canada

Re: UserForm Disappears occasionally or is partially display

Post by Don Wells »

Well !!! That didn't take long to reappear as a problem.
I have now inserted Userform1.Repaint after each instance of Application.ScreenUpdating = True. I will advise when I have gone through 2 successful weeks.
Regards
Don

User avatar
Don Wells
5StarLounger
Posts: 689
Joined: 27 Jan 2010, 16:45
Location: Ottawa, Ontario, Canada

Re: UserForm Disappears occasionally or is partially displayed

Post by Don Wells »

It has now been 3 weeks without a problem and it appears that the main contributor to my problem was that the VB Editor was open. Only time will tell. I will advise if the problem reappears.
Regards
Don

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: UserForm Disappears occasionally or is partially displayed

Post by HansV »

Let's hope it stays that way! :crossfingers:
Best wishes,
Hans

User avatar
Don Wells
5StarLounger
Posts: 689
Joined: 27 Jan 2010, 16:45
Location: Ottawa, Ontario, Canada

Re: UserForm Disappears occasionally or is partially displayed

Post by Don Wells »

I think that we can finally put this topic to bed.
I was using the Wait method and failed to recognize the following remark from Excel Help:
The Wait method suspends all Microsoft Excel activity and may prevent you from performing other operations on your computer while Wait is in effect. However, background processes such as printing and recalculation continue.
I have since replaced the Wait method with a Do Loop based on the Timer function.
Regards
Don

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: UserForm Disappears occasionally or is partially displayed

Post by HansV »

Glad you found a solution!
Best wishes,
Hans

LisaGreen
5StarLounger
Posts: 964
Joined: 08 Nov 2012, 17:54

Re: UserForm Disappears occasionally or is partially displayed

Post by LisaGreen »

Good catch Don!!

Lisa