Delay Between running functions

stu_c

Registered User.
Local time
Today, 19:20
Joined
Sep 20, 2007
Messages
494
Hi all
when a user presses a button it automatically loads up a web page fills it out then closes it down then opens another webpage as a report, I need to be able to put a delay between the page loading then to close, how can I do this?

Private Sub BtnUpdateRecords()
FUNC_Webpage_OPEN
[DELAY HERE]
FUNC_Webpage_CLOSE
FUNC_WebpageReport_OPEN
End Sub
 
One approach is you could try a timer loop or perhaps use the ShellWait API.
 
I just did something like this yesterday. I used the code from here.


I added the below to the top of my form module

Code:
Private Declare Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)

Then just Sleep 500 between the lines I wanted the delay. Works nicely for me.

Just amend the number for the delay you want.

~Matt
 
the
Private Declare Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)

where do I put this a module / class?
 
If you want to use a library function such as this one, the declaration must go in the declarations section of the form's class module (since you used "Private" in the definition.) Basically, define it in the context where it will be used.

If you have a general module you could stick the PUBLIC variant of this in the declarations section of the general module. It would work equally well being declared as public.
 
If you want to use a library function such as this one, the declaration must go in the declarations section of the form's class module (since you used "Private" in the definition.) Basically, define it in the context where it will be used.

If you have a general module you could stick the PUBLIC variant of this in the declarations section of the general module. It would work equally well being declared as public.
Thank you for the reply, you are basically talking another language to me I genuinely have no idea how to do that, I have only just learnt how to do Functions

all I did was select the button, go to properties then on Click
 
I need to be able to put a delay between the page loading then to close
Just a thought: the delay is needed for the web page to load completely?
How long would you want to wait then?
Maybe there is also the possibility to check if the page was loaded completely instead of waiting a certain time.
 
Just a thought: the delay is needed for the web page to load completely?
How long would you want to wait then?
Maybe there is also the possibility to check if the page was loaded completely instead of waiting a certain time.
hello, it is milli seconds, I just need a slight delay from opening to closing it as sometimes it does it far too quick and hasnt got enough time to realise it is open and produces an error that's all
 
OK, here's a learning experience for you. When you create subroutines and functions, they go into one or more code modules. Each module can be part of a form (in which case it is called a class module or sometimes a form's class module). It could also be an independent module, sometimes called a general module. Modules that are part of the form are usually set aside for code specific to that form. Modules intended to be shared are best placed in general modules.

Modules have two basic parts. Before you create any functions or subroutines, you are at the top of the module, which is called the declaration area. You can declare variables in that area, but you can ALSO define linkages to external subroutines. That "Private Declare" line is an example of a declaration of an external, library-based subroutine. By declaring it private, you make that definition available ONLY to the functions and subroutines in the module in which the declaration occurred. If you made it a "PUBLIC Declare" line in a general module, you could define it just once for your entire project. That is because you generally use PRIVATE declarations in a form's class module, and are more likely to use PUBLIC declarations in general modules - because you are more likely to share that code among multiple forms & reports.

Once you have declared your module's variables in the declaration area, you start defining the functions and subroutines for that module. VBA will complain if you make declarations in a module outside of any executable code but after the first executable element has been declared. Note that the PRIVATE keyword still works even when in a general module, so a PRIVATE variable in a general module cannot be seen from code in other modules. A PRIVATE subroutine cannot be called from outside the module. And a PRIVATE function reference is only visible to members of the module where it was defined.
 

Users who are viewing this thread

Back
Top Bottom