Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

progress bar in macro populating sheets from a selected listbox value

Posted on 2014-01-22
2
Medium Priority
?
430 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 1500 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

886 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