Partager via


Connection.Cancel, méthode (DAO)

S’applique à : Access 2013, Office 2013

Syntaxe

expression . Annuler

expression Variable qui représente un objet Connection.

Remarques

Utilisez la méthode Cancel pour mettre fin à l’exécution d’un appel de méthode Execute ou OpenConnection asynchrone (autrement dit, la méthode a été appelée avec l’option dbRunAsync). Cancel renvoie une erreur d’exécution si dbRunAsync n’a pas été utilisé dans la méthode que vous essayez d’arrêter.

Une erreur se produira si, après un appel de la méthode Cancel, vous tentez de référencer l'objet qui aurait été créé par une appel de la méthode OpenConnection asynchrone (à savoir, l'objet Connection à partir duquel vous avez appelé la méthode Cancel).

Exemple

Cet exemple utilise la propriété StillExecuting et la méthode Cancel pour ouvrir un objet Connection en mode asynchrone.

    Sub CancelConnectionX() 
     
     Dim wrkMain As Workspace 
     Dim conMain As Connection 
     Dim sngTime As Single 
     
     Set wrkMain = CreateWorkspace("ODBCWorkspace", _ 
     "admin", "", dbUseODBC) 
     ' Open the connection asynchronously. 
     
     ' Note: The DSN referenced below must be configured to 
     ' use Microsoft Windows NT Authentication Mode to 
     ' authorize user access to the Microsoft SQL Server. 
     Set conMain = wrkMain.OpenConnection("Publishers", _ 
     dbDriverNoPrompt + dbRunAsync, False, _ 
     "ODBC;DATABASE=pubs;DSN=Publishers") 
     
     sngTime = Timer 
     
     ' Wait five seconds. 
     Do While Timer - sngTime < 5 
     Loop 
     
     ' If the connection has not been made, ask the user 
     ' if she wants to keep waiting. If she does not, cancel 
     ' the connection and exit the procedure. 
     Do While conMain.StillExecuting 
     
     If MsgBox("No connection yet--keep waiting?", _ 
     vbYesNo) = vbNo Then 
     conMain.Cancel 
     MsgBox "Connection cancelled!" 
     wrkMain.Close 
     Exit Sub 
     End If 
     
     Loop 
     
     With conMain 
     ' Use the Connection object conMain. 
     .Close 
     End With 
     
     wrkMain.Close 
     
    End Sub