Solved

Progress Bar

Posted on 2007-03-27
3
260 Views
Last Modified: 2010-05-18
Hi: How to i fixed the progress bar so that it will shows the estimated time and value in percentage that how much is done. Right now the way i used is, just start from 1 and when it goes to 100 then it again 0.

Private Sub QueryProcess()
Dim DBConn
Dim xlApp As Excel.Application
Dim xlWb As Excel.Workbook
Dim xlWS As Excel.Worksheet
Dim rngColumn As Excel.Range
Dim rngCell As Excel.Range
Dim strSource As String
Dim mysheet As String
Dim lngRow As Long
ProgressBar2.Value = 1
ProgressBar2.Value = 10
ProgressBar2.Value = 20
ProgressBar2.Value = 30

Dim rs
'This is Adaptive Server Enterprise Connection
Set DBConn = CreateObject("ADODB.Connection")
DBConn.Open "ODBC; Driver=Adaptive Server Anywhere 6.0; DSN=Debtmaster; uid=dm; pwd=,,PeAches..;"
Dim sSQL As String
sSQL = "select clt_ref_no as CFG_ACCOUNT, " & _
"(case  " & _
"when r.status_code in ('400','404','407') then 'OVBK' " & _
"when r.status_code in ('210','420','430','470','630') then 'OVUN' " & _
"when r.status_code in ('435') then 'OVRC' " & _
"when r.status_code in ('450') then 'OVDC' " & _
"when r.status_code in ('487','485') then 'OVFA' " & _
"when r.status_code = '491' then 'OCAC' " & _
"when r.status_code = '510' then 'OSIF' " & _
"when r.status_code='520' then 'OPIF' " & _
"else 'CHECK STATUS' " & _
"END) as REASON, " & _
"(SELECT LONGSTR FROM DBTRUDF U WHERE R.DEBTOR_ID=U.DEBTOR_ID AND LABEL='BANKRUPTCYCHAPTER' and reason='OVBK') AS BANKRUPTCYCHAPTER, " & _
"(SELECT LONGSTR FROM DBTRUDF U WHERE R.DEBTOR_ID=U.DEBTOR_ID AND LABEL='CASENUMBER' and reason='OVBK') AS CASENUM, " & _
"CONVERT(CHAR(10),(SELECT DATE1 FROM DBTRUDF U WHERE R.DEBTOR_ID=U.DEBTOR_ID and reason='OVBK' AND LABEL='FILEDATE'),101) AS BKTFILEDATE, " & _
"CONVERT(CHAR(10),(SELECT DATE1 FROM DBTRUDF U WHERE R.DEBTOR_ID=U.DEBTOR_ID and reason='OVBK' AND LABEL='DECEASEDDATE'),101) AS DATEOFDEATH, " & _
"STATUS_DESCR AS COMMENTS, " & _
"    substring(DEBT_DESCR,(LOCATE(DEBT_DESCR,':',1)+1), 30) AS ORIGINALACCOUNT " & _
"FROM DEBT_VIEW S JOIN DBTR R ON S.DEBT_ID=R.DEBTOR_ID " & _
"WHERE CLT_ID LIKE 'IDTC%' AND R.STATUS_CODE>='400'  AND R.STATUS_DATE>'2007-02-25' "

Set rs = DBConn.Execute(sSQL)

strSource = "\\usnymel1fs001\new claims\IDT Carmel\upload\" & "Close And Returns File" & " " & Format(Date, "MMDDYY") & ".xls"
Set xlApp = New Excel.Application
'Set xlWb = xlApp.Workbooks.Open(strSource)
Set xlWb = xlApp.Workbooks.Add 'this creates a new, blank workbook
mysheet = xlApp.Worksheets(1).Name
xlApp.Columns("A:H").EntireColumn.AutoFit
Set xlWS = xlWb.Worksheets(mysheet)
xlWS.Range("A1").Value = "CFG_ACCOUNT"
xlWS.Range("B1").Value = "STATUS"
xlWS.Range("C1").Value = "BKT CAHPTER"
xlWS.Range("D1").Value = "BKT CASE#"
xlWS.Range("E1").Value = "BKT FILE DATE"
xlWS.Range("F1").Value = "DATE OF DEATH"
xlWS.Range("G1").Value = "COMMENTS"
xlWS.Range("H1").Value = "ORIGINAL ACCOUNT"
lngRow = 2
Do While Not rs.EOF
    If ProgressBar2.Value >= 100 Then ProgressBar2.Value = 0
    ProgressBar2.Value = ProgressBar2.Value + 1
    xlWS.Cells(lngRow, 1).Value = rs!CFG_ACCOUNT
    xlWS.Cells(lngRow, 2).Value = rs!REASON
    xlWS.Cells(lngRow, 3).Value = rs!BANKRUPTCYCHAPTER
    xlWS.Cells(lngRow, 4).Value = rs!CASENUM
    xlWS.Cells(lngRow, 5).Value = rs!BKTFILEDATE
    xlWS.Cells(lngRow, 6).Value = rs!DATEOFDEATH
    xlWS.Cells(lngRow, 7).Value = rs!Comments
    xlWS.Cells(lngRow, 8).Value = rs!ORIGINALACCOUNT
    lngRow = lngRow + 1
    rs.MoveNext
Loop

xlWb.Close SaveChanges:=True, FileName:=strSource
Set xlWb = Nothing
Set xlWS = Nothing
xlApp.Quit
Set xlApp = Nothing
Unload Me
ShellExecute 0, vbNullString, Chr(34) & strSource & Chr(34), vbNullString, strSource, vbMaximizedFocus
End Sub
0
Comment
Question by:mustish1
3 Comments
 
LVL 11

Accepted Solution

by:
TreyH earned 250 total points
ID: 18805485
If you want the progress bar to reflect moving through the recordset then you could do something like this:


ProgressBar2.Min = 1
ProgressBar2.Max = rs.RecordCount
ProgressBar2.Value = 0

Do While Not rs.EOF

    If ProgressBar2.Value < ProgressBar2.Max Then
      ProgressBar2.Value = ProgressBar2.Value + 1
    End If

    ProgressBar2.Value = ProgressBar2.Value + 1
    xlWS.Cells(lngRow, 1).Value = rs!CFG_ACCOUNT
    xlWS.Cells(lngRow, 2).Value = rs!REASON
    xlWS.Cells(lngRow, 3).Value = rs!BANKRUPTCYCHAPTER
    xlWS.Cells(lngRow, 4).Value = rs!CASENUM
    xlWS.Cells(lngRow, 5).Value = rs!BKTFILEDATE
    xlWS.Cells(lngRow, 6).Value = rs!DATEOFDEATH
    xlWS.Cells(lngRow, 7).Value = rs!Comments
    xlWS.Cells(lngRow, 8).Value = rs!ORIGINALACCOUNT
    lngRow = lngRow + 1
    rs.MoveNext
Loop
0
 

Author Comment

by:mustish1
ID: 18805503
Thanks. Can you also please tell me how to i show the estimated time with the bar?
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points
ID: 18805869
note: you need a Doevents call in the loop to give the progressbar the chance to refresh, otherwise you won't see anything.

>Can you also please tell me how to i show the estimated time with the bar?
there are several techniques.
* don't use a progress bar.
* progress up to 50% with incrementing by 1 for each record, then starting incrementing only by 0.5 until 80%, then only by 0.20 until 90% etc...
* get the exact number of records to be processed, that way you are sure that the progressbar.max is correct.



0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question