Solved

Progress Bar

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now