Consulting

Results 1 to 8 of 8

Thread: Automating selection of checkboxes in SSRS by label name

  1. #1

    Automating selection of checkboxes in SSRS by label name

    Long story short, using VBA I'm trying to automate the selection of items from multi-value dropdown boxes and run SQL Server Reporting Services (SSRS).

    I'm able to get to the page and start to make selections, but I need to check if the element's LABEL equals a certain value. I seem to be unable to locate a simple way to snag the label, as innertext and innerhtml seem to return blank spaces. The goal will be to have a list of names in Excel to match by elementID LABELS and then run the data.

    If anyone has a method to scrape the label names for these, I'd LOVE to be able to incorporate it. Any assistance will be highly appreciated.


    Sub UM51f()
    Dim objIE, element
    Dim SSRS As String
        Set objIE = CreateObject("InternetExplorer.Application")
        SSRS = [Link to SSRS here]
        With objIE
            .Visible = True
            .navigate SSRS
            Do Until .readyState = 4
                DoEvents
            Loop
            .navigate [specific SSRS report link here]
            Do Until .readyState = 4
                DoEvents
            Loop
    'drop down for selection
    Set element = .document.getelementbyid("ctl32_ctl04_ctl03_ddDropDownButton")
        element.Click
    'This is where I need to check to see if the element's label = a specific name:
    Set element = .document.getelementbyid("ctl32_ctl04_ctl03_divDropDown_ctl02")
        'trying to print the values to see if they contain usable info:
        Debug.Print .document.getelementbyid("ctl32_ctl04_ctl03_divDropDown_ctl02").innertext
        Debug.Print .document.getelementbyid("ctl32_ctl04_ctl03_divDropDown_ctl02").innerhtml
        element.Click
    'More selections:
    Set element = .document.getelementbyid("ctl32_ctl04_ctl03_divDropDown_ctl03")
        element.Click
    Set element = .document.getelementbyid("ctl32_ctl04_ctl03_divDropDown_ctl04")
        element.Click
        End With
    'A few more steps and then submit
    End Sub
    Sample script data I'm referencing:
    <table cellpadding="0" cellspacing="0" style="background-color:window;">
    <tr>
    <td nowrap="nowrap"><span><input id="ctl32_ctl04_ctl03_divDropDown_ctl00" type="checkbox" name="ctl32$ctl04$ctl03$divDropDown$ctl00" onclick="$get('ctl32_ctl04_ctl03').control.OnSelectAllClick(this);" /><label for="ctl32_ctl04_ctl03_divDropDown_ctl00">(Select All)</label></span></td>
    </tr><tr>
    <td nowrap="nowrap"><span><input id="ctl32_ctl04_ctl03_divDropDown_ctl02" type="checkbox" name="ctl32$ctl04$ctl03$divDropDown$ctl02" onclick="$get('ctl32_ctl04_ctl03').control.OnValidValueClick(this, 'ctl32_ctl04_ctl03_divDropDown_ctl00');" /><label for="ctl32_ctl04_ctl03_divDropDown_ctl02">Name1</label></span></td>
    </tr><tr>
    <td nowrap="nowrap"><span><input id="ctl32_ctl04_ctl03_divDropDown_ctl03" type="checkbox" name="ctl32$ctl04$ctl03$divDropDown$ctl03" onclick="$get('ctl32_ctl04_ctl03').control.OnValidValueClick(this, 'ctl32_ctl04_ctl03_divDropDown_ctl00');" /><label for="ctl32_ctl04_ctl03_divDropDown_ctl03">Name2</label></span></td>
    </tr><tr>

  2. #2
    Oh, and this is in IE8. Forgot to include that in the original post

  3. #3
    I suppose one method could be to extract the Script text and write a small search function? If I went this route, is there a good method to obtain the script source in a way that VBA can search it? I've done this with HTML, but very unsure how to in this situation.

  4. #4
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,710
    Location
    For="ctl32_ctl04_ctl03_divDropDown_ctl00">(Select All)</label>

    http://www.w3schools.com/jsref/dom_obj_label.asp :html For Sets or returns the value of the for attribute of a label



    Maybe
    X = document.getElementById("ctl32_ctl04_ctl03_divDropDown_ctl00").getAttribute("Label").InnerText
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  5. #5
    Thanks for the reply. Unfortunately testing with the following produced a 424 Object Required error.

    Debug.Print .document.getElementById("ctl32_ctl04_ctl03_divDropDown_ctl00").getAttribute("Label").InnerText

  6. #6
    I made an ugly method to get me what I needed. It uses sendkeys, but so far it hasn't had an error after about 25 tests.

    In short, the code opens IE and gets to the report page
    SendKeys simulates F12 to open Dev tools
    More sendkeys to get to the Script tab and select/copy it.
    Open Notepad
    Paste
    Save and close

    Back in IE, iterate through each of the checkboxes by id to see if the label (name) is on a list. If so, check the box.
    then finish the report and export..


    Appreciate the help, thought I'd give my .02 should someone else be looking to do something similar. I don't like using sendkeys, but so fat after about 25 tests, it seems to preform this task ok.

  7. #7
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,710
    Location
    Thanks for sharing your solution.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  8. #8
    thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •