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.
Delay in VBA
Collapse
X
-
Tags: None
-
The Sleep(milliseco nds) 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:Originally posted by Robertf987Hi. 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.
You can now call this Sub-Routine from anywhere in your application:Code:Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Code:Call Sleep(5000) [B]'The Message Box will not appear for 5 seconds[/B] MsgBox "5 seconds have passed"
-
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:
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.Code:Private Sub Form_Open(Cancel As Integer) Dim T T = 0 Form.AllowDesignChanges = True ProgressBox.Width = T Do Call Sleep(100) T = T + 50 ProgressBox.Width = T Loop Until T = 3500 End Sub
Comment
Comment