Solved

progress bar in macro populating sheets from a selected listbox value

Posted on 2014-01-22
2
381 Views
Last Modified: 2014-01-29
folks

I have a listbox where if a item is selected in the listbox , a call gets made to the oracle db and downloads the associated records into sheet2

how though do I call up a progress bar to show status on the time when data is being downloaded and populated into the sheet

keen for your thoughts

here is my code:


Private Sub ListBox1_Click()

'Dim r As Long
'r = Sheet1.Range("A1").Offset(Sheet1.Rows.Count - 2, 0).End(xlUp).Row
   
   
MsgBox "Select * from Workorder where  " & ListBox1.Value & ""
Sheets(2).Range("A1").Value = "Select * from projects where " & ListBox1.Value
Sheets(2).Range("A3:IV65536").ClearContents

    Dim strConOracle As String
    Dim strTemp As String
    Dim oConOracle, oRsOracle
    Dim strSQL As String
    Dim lngCount As Long
    Dim strCount As String
    Dim DBNAME As String
    Dim HOST As String
    Dim ORACLE_USER_NAME As String
    Dim ORACLE_PASSWORD As String
    ORACLE_PASSWORD = Range("D2").Value
    DBNAME = Range("A2").Value
    HOST = Range("B2").Value
    ORACLE_USER_NAME = Range("C2").Value

   
    strConOracle = "Driver={Microsoft ODBC for Oracle}; CONNECTSTRING=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)"
    strConOracle = strConOracle & "(HOST=" & HOST & ")(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=" & DBNAME
    strConOracle = strConOracle & "))); uid=" & ORACLE_USER_NAME & " ;pwd=" & ORACLE_PASSWORD & ";"
    Set oConOracle = CreateObject("ADODB.Connection")
    Set oRsOracle = CreateObject("ADODB.RecordSet")
    oConOracle.Open strConOracle
   
 
strSQL = "SELECT task,description,owner from projects WHERE  " & ListBox1.Value & ""

   
   
    Set oRsOracle = oConOracle.Execute(strSQL)

   
    lngCount = 2
       
        Do While Not oRsOracle.EOF
       
 
       
            DoEvents
            lngCount = lngCount + 1
            strCount = Trim(Str(lngCount))
       
           
            If Not IsNull(oRsOracle.Fields(0).Value) Then
                strTemp = oRsOracle.Fields(0).Value
           Else
                strTemp = ""
            End If
            If strTemp = "" Then strTemp = "Not Captured"
            Sheet2.Range("A" & strCount).FormulaR1C1 = strTemp
           
           
           
            If Not IsNull(oRsOracle.Fields(1).Value) Then
                strTemp = oRsOracle.Fields(1).Value
            Else
                strTemp = ""
           End If
            If strTemp = "" Then strTemp = "Not Populated"
            Sheet2.Range("B" & strCount).FormulaR1C1 = strTemp
           
           
           
            If Not IsNull(oRsOracle.Fields(2).Value) Then
                strTemp = oRsOracle.Fields(2).Value
            Else
               strTemp = ""
            End If
            If strTemp = "" Then strTemp = "Sched Start"
            Sheet2.Range("C" & strCount).FormulaR1C1 = strTemp
           
       
       
            If Not IsNull(oRsOracle.Fields(3).Value) Then
                strTemp = oRsOracle.Fields(3).Value
            Else
               strTemp = ""
            End If
            If strTemp = "" Then strTemp = "No Sched Finish"
            Sheet2.Range("D" & strCount).FormulaR1C1 = strTemp
           
           
            If Not IsNull(oRsOracle.Fields(4).Value) Then
                strTemp = oRsOracle.Fields(4).Value
            Else
               strTemp = ""
            End If
            If strTemp = "" Then strTemp = "Status"
            Sheet2.Range("E" & strCount).FormulaR1C1 = strTemp
           
            oRsOracle.MoveNext
    Loop
    oConOracle.Close
    Set oRsOracle = Nothing
    Set oConOracle = Nothing




r
0
Comment
Question by:rutgermons
  • 2
2 Comments
 
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 39801960
0
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 500 total points
ID: 39801973
actually i think i misread your q somewhat.....

have a look at the second link...

it uses displays a userform while the process occurs and this form can be updated to show progress if desired. then unloaded.
to test, create a new userform <MyProgress> and add a text box to it

    MyProgress.Show
    lngCount = 2
        
        Do While Not oRsOracle.EOF
            DoEvents
            lngCount = lngCount + 1
            if lngCount Mod 10 = 0 then
                   MyProgress.textbox1.text = MyProgress.textbox1.text & "#"
            end if

            '......

       loop
      MyProgress.Hidden = true

Open in new window


it should show a line of ### move as progress occurs.  Can add an abort button if needed.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

762 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