Solved

progress bar in macro populating sheets from a selected listbox value

Posted on 2014-01-22
2
397 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

770 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