PC Review


Reply
Thread Tools Rate Thread

Display and close form automatically

 
 
Billy Rogers
Guest
Posts: n/a
 
      12th Oct 2007
Here's some code I'm working on. I want to display a message to the
user for approximately 3 seconds and then continue on with the code.
I've built a form with a message written on it. When i run this code
the form displays and then it doesn't do anything. The Sleep
function works fine.........I just don't know how to get the form to
close automatically.



On Error Resume Next

Shell BankNamePath, vbMaximizedFocus

If Err.Number = 5 Or Err.Number = 53 Then

UserForm1.Show
Sleep 3000
Unload UserForm1

Call OpenDefaultDiscTray
Sleep 5000
Call CloseDefaultDiscTray

Shell BankNamePath, vbMaximizedFocus

End If

 
Reply With Quote
 
 
 
 
JW
Guest
Posts: n/a
 
      12th Oct 2007
try:
Application.Wait Now + TimeValue("00:00:03")
Unload UserForm1

Billy Rogers wrote:
> Here's some code I'm working on. I want to display a message to the
> user for approximately 3 seconds and then continue on with the code.
> I've built a form with a message written on it. When i run this code
> the form displays and then it doesn't do anything. The Sleep
> function works fine.........I just don't know how to get the form to
> close automatically.
>
>
>
> On Error Resume Next
>
> Shell BankNamePath, vbMaximizedFocus
>
> If Err.Number = 5 Or Err.Number = 53 Then
>
> UserForm1.Show
> Sleep 3000
> Unload UserForm1
>
> Call OpenDefaultDiscTray
> Sleep 5000
> Call CloseDefaultDiscTray
>
> Shell BankNamePath, vbMaximizedFocus
>
> End If


 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      12th Oct 2007
The problem is that you are displaying the form "modally". When you do this,
on the line of code

UserForm1.Show

code execution pauses at that line until the form is hidden (of course, code
within UserForm1 can still run). Only after the form is hidden or unloaded
will the code continue execution at the next line after the Show method. In
Excel 2000 and later, you can display the form "modelessly", in which case
the form is shown an execution continues while the form is displayed.

UserForm1.Show vbModeless


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"Billy Rogers" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Here's some code I'm working on. I want to display a message to the
> user for approximately 3 seconds and then continue on with the code.
> I've built a form with a message written on it. When i run this code
> the form displays and then it doesn't do anything. The Sleep
> function works fine.........I just don't know how to get the form to
> close automatically.
>
>
>
> On Error Resume Next
>
> Shell BankNamePath, vbMaximizedFocus
>
> If Err.Number = 5 Or Err.Number = 53 Then
>
> UserForm1.Show
> Sleep 3000
> Unload UserForm1
>
> Call OpenDefaultDiscTray
> Sleep 5000
> Call CloseDefaultDiscTray
>
> Shell BankNamePath, vbMaximizedFocus
>
> End If
>


 
Reply With Quote
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      12th Oct 2007
Chips answer is spot on. That being said the other way to make the form
disappear after a short period of time is to place the code into the forms
Activate event, something like this (th eform does not need to be shown
modeless)...

Private Sub UserForm_Activate()
Application.Wait Now + TimeSerial(0, 0, 3)
Me.Hide
End Sub

The benefit to this is if you intend to use this same form in multiple
places then you do not need to keep on re-writing the same code. If you don't
intend to re-use this form then there is absolutely no benefit.
--
HTH...

Jim Thomlinson


"Chip Pearson" wrote:

> The problem is that you are displaying the form "modally". When you do this,
> on the line of code
>
> UserForm1.Show
>
> code execution pauses at that line until the form is hidden (of course, code
> within UserForm1 can still run). Only after the form is hidden or unloaded
> will the code continue execution at the next line after the Show method. In
> Excel 2000 and later, you can display the form "modelessly", in which case
> the form is shown an execution continues while the form is displayed.
>
> UserForm1.Show vbModeless
>
>
> --
> Cordially,
> Chip Pearson
> Microsoft MVP - Excel, 10 Years
> Pearson Software Consulting
> www.cpearson.com
> (email on the web site)
>
> "Billy Rogers" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Here's some code I'm working on. I want to display a message to the
> > user for approximately 3 seconds and then continue on with the code.
> > I've built a form with a message written on it. When i run this code
> > the form displays and then it doesn't do anything. The Sleep
> > function works fine.........I just don't know how to get the form to
> > close automatically.
> >
> >
> >
> > On Error Resume Next
> >
> > Shell BankNamePath, vbMaximizedFocus
> >
> > If Err.Number = 5 Or Err.Number = 53 Then
> >
> > UserForm1.Show
> > Sleep 3000
> > Unload UserForm1
> >
> > Call OpenDefaultDiscTray
> > Sleep 5000
> > Call CloseDefaultDiscTray
> >
> > Shell BankNamePath, vbMaximizedFocus
> >
> > End If
> >

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically Close a Form =?Utf-8?B?S2V6?= Microsoft Access 3 12th Aug 2008 04:59 AM
Automatically close a form Rafi Microsoft Access Forms 1 22nd Mar 2008 09:29 PM
close form automatically after say 2 second Song Su Microsoft Access Forms 4 6th Jul 2007 02:34 PM
Is it possible to have a messageBox to display for 2 sec's and then Close AUTOMATICALLY ? Corey Microsoft Excel Programming 3 26th Feb 2007 01:18 AM
Close form automatically RogerC Microsoft Outlook Form Programming 2 11th May 2004 06:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:06 PM.