Presentation is loading. Please wait.

Presentation is loading. Please wait.

Source: Link Posted By: HeelpBook Permalink: Link

Similar presentations


Presentation on theme: "Source: Link Posted By: HeelpBook Permalink: Link"— Presentation transcript:

1 Source: Link Posted By: HeelpBook Permalink: Link
28/05/2019 Excel – VBA Execute stored procedure from VBA without waiting for completion Source: Link Posted By: HeelpBook Permalink: Link 28/05/2019 How-Tos <<

2 HeelpBook © 28/05/2019 SCENARIO I am trying to execute an SQL stored procedure from within VBA. I have been successful in doing this but my stored procedure can take up to 5 minutes to complete. During this time Excel will appear frozen to the user. I would like to execute the procedure and continue on through my code without waiting for the procedure to complete. Is this possible? Thanks in advance. 28/05/2019 >> Execute stored procedure from VBA without waiting for completion How-Tos <<

3 HeelpBook © 28/05/2019 Here's my existing code: Public Sub connect() Dim Cnxn As New ADODB.Connection Dim cmd As New ADODB.Command Dim strCnxn As String   28/05/2019 >> Execute stored procedure from VBA without waiting for completion How-Tos <<

4 HeelpBook © 28/05/2019 strCnxn =3D "Dsn=3DApropos3b;" & _ "Driver=3D{INFORMIX BIT};" & _ "Server=3Don_b;" & _ "Service=3D1901;" & _ "Protocol=3Donsoctcp;" & _ "Database=3Datb;" & _ "UID=3Dinformix;" & _ "PWD=3DUniteK;" Cnxn.Open strCnxn     28/05/2019 >> Execute stored procedure from VBA without waiting for completion How-Tos <<

5 HeelpBook © 28/05/2019 With cmd .ActiveConnection =3D Cnxn .CommandText =3D "sp_otb_rpt()" .CommandType =3D adCmdStoredProc .Execute End With 28/05/2019 >> Execute stored procedure from VBA without waiting for completion How-Tos <<

6 HeelpBook © 28/05/2019 SOLUTION   You can use the AsynchExecute option to execute the stored procedure asynchronously. Dim cmd As ADODB.Command Set cmd = New ADODB.Command   28/05/2019 >> Execute stored procedure from VBA without waiting for completion How-Tos <<

7 HeelpBook © 28/05/2019 cmd.ActiveConnection = "DSN = test" cmd.CommandTimeout = 180 cmd.CommandText = "sp_name" cmd.CommandType = adCmdStoredProc cmd.Execute , , adAsyncExecute   28/05/2019 >> Execute stored procedure from VBA without waiting for completion How-Tos <<

8 HeelpBook © 28/05/2019 'If you don't want the user doing anything else while the query is executing   Do While cmd.State = adStateExecuting 'or 4 DoEvents   'Options here include a timer to update the form or putting a cancel button on the sheet 'so the application does not appear to be frozen.   Loop 28/05/2019 >> Execute stored procedure from VBA without waiting for completion How-Tos <<

9 HeelpBook © 28/05/2019 That’s all Folks Come visit us on to find and read more documents and guides… AND / OR Subscribe to our feed RSS: Link Or see&read us on FeedBurner: Link { 28/05/2019 >> Execute stored procedure from VBA without waiting for completion How-Tos <<


Download ppt "Source: Link Posted By: HeelpBook Permalink: Link"

Similar presentations


Ads by Google