473,387 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Delay in VBA

Hi. I wonder if anybody can help me, I want to put a delay in my macro code. I want it to do the code, then wait say 500 miliseconds, then carry on. Can anybody help? Thanks.
Apr 16 '07 #1
2 13154
ADezii
8,834 Expert 8TB
Hi. I wonder if anybody can help me, I want to put a delay in my macro code. I want it to do the code, then wait say 500 miliseconds, then carry on. Can anybody help? Thanks.
The Sleep(milliseconds) API Routine is just what you are looking for. This Routine suspends program execution for a specified number of milliseconds. First, place this Declaration in a Standard Code Module:
Expand|Select|Wrap|Line Numbers
  1. Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
You can now call this Sub-Routine from anywhere in your application:
Expand|Select|Wrap|Line Numbers
  1. Call Sleep(5000)
  2.  
  3. 'The Message Box will not appear for 5 seconds
  4. MsgBox "5 seconds have passed"
Apr 16 '07 #2
Thanks loads for the help. I can get the delay to work for simple things like the text box, or to delay opening a form with the code you gave me. However, what I wanted it for, I can't get it to work. What I wanted was to make a progress bar. With a short delay, it would make the bar longer. I'd do it in a loop and then exit the loop once it reaches a certain length. I just want some animation to show that it is actually doing something. For some reason, I can't do this. I thought it would be simple once I know how to make a delay. I used this code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2. Dim T
  3. T = 0
  4. Form.AllowDesignChanges = True
  5. ProgressBox.Width = T
  6. Do
  7.   Call Sleep(100)
  8.   T = T + 50
  9.   ProgressBox.Width = T
  10. Loop Until T = 3500
  11. End Sub
But it doesn't work. it just does nothing. Any suggestions? I can't insert an animated gif (I'm using access 2000, I can't put in an animated gif). I've searched my big Access 2000 book and there's nothing in there about progress bars.
Apr 16 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Des L. Davis | last post by:
System: Dell PowerEdge Server with 3 GB RAM, 2.4 GHz Celeron Software: Microsoft SQL Server 2000 Enterprise running on Windows 2003 Server Software: Microsoft SQL Server 2000 Enterprise running on...
2
by: amos_s12 | last post by:
Hello everybody Is there a possibility to make a delay between two sql statements, namely one sql statement is performed, then there is a delay of some seconds and then rhe next statement is...
6
by: lucifer | last post by:
hi i need to insert delay in my program what function should i use the old delay is not supported by the VC6
20
by: Doug Thews | last post by:
I ran into an interesting re-pain delay after calling the Abort() method on a thread, but it only happens the very first time I call it. Every time afterward, there is no delay. I've got a...
11
by: Maheshkumar.R | last post by:
Hi groups, How i can introduce some milliseconds delay in application. How i can do achieve this... let me clearly say... (1) I'm displaying slices of medical images. For framerate - for...
7
by: mfeingold | last post by:
I am working on a system, which among other things includes a server and a ..net control sitting in an html page and connected to the server. I ran into a couple of problems, you guys might have...
4
by: Jeremy S | last post by:
I have written an ASP.NET application that performs very well. I make heavy use of the Cache and otherwise minimize the number of round trips to to the db. I couldn't be happier with the...
18
by: Max | last post by:
This is a follow-up on my previous thread concerning having the program wait for a certain date and time and then executing some code when it gets there. My question is; can I use the Sleep...
4
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I make a 10 second delay? ----------------------------------------------------------------------- There...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.