How to exit the program immediately?

Using VB 6 and Access 2003

I use two buttons of the command (process, cancel)

When I start the program, click the cancel button - the form is immediately downloaded.
If I click the Process button and then Cancel, the form will not be immediately uploaded.

In the Process window, I wrote the code as follows:

Getting the data from the database and creating a record set, creating a temporary table…,

Is there a way to exit the program immediately during VB code working with the database (for example, creating a recordset, creating temporary tables)?

In the Cancel button, I wrote this code

Unload me

How to exit the program immediately when it works with the database?

Help for VB 6 code required

+3
source share
4 answers

, , - , VB6 . , , VB6, ?

, ADO, . , .

, - :

Private WithEvents m_conn As ADODB.Connection
...
Set m_conn = New ADODB.Connection
Call m_conn.Open(connectionString, , , adAsyncConnect)

/ - , , , , , ):

sql = "SELECT Col1 FROM etc. etc."
Call m_conn.Execute(sql, , adAsyncExecute)

:

Call m_conn.cancel

:

Private Sub m_conn_ExecuteComplete(ByVal RecordsAffected As Long, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pCommand As ADODB.Command, ByVal pRecordset As ADODB.Recordset, ByVal pConnection As ADODB.Connection)
    ... do more processing etc...
End Sub

, , ; , , , .

, , , VB6 , m_conn.Execute.

- VB6 - , , , , MarkJ "classic" DoEvents - , , , . , . , , , .

.

retrieve results
...
DoEvents
...
build temporary tables
...
DoEvents

, DoEvents, "", .

.. , , , . - :

Private m_cancel as Boolean

Private Sub cmdCancel_Click()
    m_cancel = True
End Sub

Private Sub cmdProcess_Click()
    ...
    retrieve results
    ...
    DoEvents
    If Not m_cancel Then
        ... build temporary tables etc...
    End if

    If m_cancel Then Unload Me
End Sub
+8

, , "" "" , .

+4

:

End
+3
source

Soon, write more DoEvents code in the Process field.
Or use alternative DoEvents code, which is much better and faster than DoEvents. http://nirsoft.net/vb/doevents.html

-1
source

Source: https://habr.com/ru/post/1714945/


All Articles