Solved

Progress Bar

Posted on 2007-03-27
3
262 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

734 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