Is possible to show a progressbar during sql exceution until query finish?
Note:
i use ado, vb6 classic and Access database
Progress Bar During Query
-
- Administrator
- Posts: 78556
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- PlatinumLounger
- Posts: 4364
- Joined: 26 Apr 2010, 17:36
Re: Progress Bar During Query
HansV wrote:I don't think so, sorry.
googling...
Code: Select all
Option Explicit
Private WithEvents oRS As ADODB.Recordset
Private Sub Form_Load()
Dim oConn As ADODB.Connection
Set oConn = New ADODB.Connection
oConn.Open "provider=sqloledb;data source=servername;initial catalog=dbname;integrated security=sspi"
Set oRS = New ADODB.Recordset
With oRS
.CursorLocation = adUseClient
.LockType = adLockReadOnly
.CursorType = adOpenStatic
.Properties("Initial Fetch Size").Value = 10
'the FetchProgress event will fire after every 500 records
.Properties("Background Fetch Size").Value = 500
End With
oRS.Open "Select * From Tablename", oConn, , , adAsyncFetch Or adCmdText
Set oRS.ActiveConnection = Nothing
'Display data from the first record.
Text1.Text = oRS.Fields(1).Value
oConn.Close
Set oConn = Nothing
End Sub
Private Sub oRS_FetchComplete(ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
ProgressBar1.Max = pRecordset.RecordCount
ProgressBar1.Value = ProgressBar1.Max
End Sub
Private Sub oRS_FetchProgress(ByVal Progress As Long, ByVal MaxProgress As Long, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
If MaxProgress > ProgressBar1.Max Then
ProgressBar1.Max = MaxProgress
End If
If Progress < ProgressBar1.Max Then
ProgressBar1.Value = Progress
Else
ProgressBar1.Value = ProgressBar1.Max
End If
End Sub
-
- Administrator
- Posts: 78556
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- PlatinumLounger
- Posts: 4364
- Joined: 26 Apr 2010, 17:36
Re: Progress Bar During Query
HansV wrote:Which part don't you understand?
in wich part of code start the progressbar, and when?
-
- Administrator
- Posts: 78556
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Progress Bar During Query
This code uses the Load event of a form to set some properties of a recordset:
before it opens the recordset. These properties ensure that the FetchProgress event of the recordset will fire.
You can call this from other code too, of course. It doesn't have to be in the Load event of a form.
The FetchProgress event procedure updates the progress bar each time 500 records have been loaded (since Background Fetch Size = 500).
The FetchComplete event occurs when all records have been loaded. It sets the progress bar to its maximum.
Code: Select all
.Properties("Initial Fetch Size").Value = 10
'the FetchProgress event will fire after every 500 records
.Properties("Background Fetch Size").Value = 500
You can call this from other code too, of course. It doesn't have to be in the Load event of a form.
The FetchProgress event procedure updates the progress bar each time 500 records have been loaded (since Background Fetch Size = 500).
The FetchComplete event occurs when all records have been loaded. It sets the progress bar to its maximum.
Best wishes,
Hans
Hans