Solved

Progress Bar

Posted on 2007-03-27
3
261 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

730 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