Bonjour !
j'ai vu plusieurs fois une demande comment créer une pause dans l'execution de votre code ...
Voici un code ou il est possible de choisir le temps de pause ou encore jusqu'a un heure spécifier. Vraiment pratique
j'Ai tiré ce code de ce lien
Donc Premièrement insérer cette déclaration en tête de module :
Pour Attendre quelques secondes appeller cette procédure :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 ' Copyright (c) FMS, Inc. www.fmsinc.com ' Licensed to owners of Total Visual SourceBook ' ' Class : modDateTime ' Description : Code for working with date and times ' ' Visual Basic provides many useful functions for dealing with date and time values. ' This module contains code that enhances these functions, with code for adding and subtracting ' dates, handling weekdays, finding the next or previous day, checking for leap years, ' determining ages, calculating differences between dates/times, and more. ' Source : Total Visual SourceBook Private Declare Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)
Procédure à placer dans un module séparé exemple "mod_waitseconds"
Exemple d'appel :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 Public Sub WaitSeconds(intSeconds As Integer) ' Comments: Waits for a specified number of seconds ' Params : intSeconds Number of seconds to wait ' Source : Total Visual SourceBook On Error GoTo PROC_ERR Dim datTime As Date datTime = DateAdd("s", intSeconds, Now) Do ' Yield to other programs (better than using DoEvents which eats up all the CPU cycles) Sleep 100 DoEvents Loop Until Now >= datTime PROC_EXIT: Exit Sub PROC_ERR: MsgBox "Error: " & Err.Number & ". " & Err.Description, , "modDateTime.WaitSeconds" Resume PROC_EXIT End Sub
Pour attendre une heure pré-déterminée :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 MsgBox "Cette application va se fermer dans 5 secondes." WaitSeconds (5) docmd.Quit
Procédure a placer dans un module séparé exemple "mod_WaitForTime" :
Exemple d'appel :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 Public Sub WaitForTime(datDate As Date) ' Comments: Waits until the specified date and time ' Params : datDate Date/time to wait for ' Source : Total Visual SourceBook On Error GoTo PROC_ERR Do ' Yield to other programs (better than using DoEvents which eats up all the CPU cycles) Sleep 100 DoEvents Loop Until Now >= datDate PROC_EXIT: Exit Sub PROC_ERR: MsgBox "Error: " & Err.Number & ". " & Err.Description, , "modDateTime.WaitForTime" Resume PROC_EXIT End Sub
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 ' Fermer Access a 11:59 PM WaitForTime (Date + #11:59:00 PM#)
Partager