Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    lonesoac0 is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Aug 2014
    Posts
    36

    Html <tr> that must go away!


    Hello all,

    I have a report that is generated in HTML and I must get rid of the first <tr></tr>. I have discussed things with the vendor and that first row is hard coded and will not come out through the reporting program. As a result, I would like a macro that removes the first row. Below is the general gist what I want gone. I have reviewed other reports generated and they have the same 0, 137, 108, 214, and 176 values. The line number values are 90 to 96 consistently across reports too.

    HTML Code:
    <table cellpadding="0" cellspacing="0" border="0" style="border-width:0px;empty-cells:show;width:635px;height:44px;">
        <tr>
            <td style="width:0px;height:0px;"></td>
            <td style="height:0px;width:137px;"></td>
            <td style="height:0px;width:108px;"></td>
            <td style="height:0px;width:214px;"></td>
            <td style="height:0px;width:176px;"></td>
        </tr>
        <tr style="vertical-align:top;">
            <td style="width:0px;height:22px;"></td>
            <td class="csD4A184AD" style="width:133px;height:22px;text-align:left;vertical-align:top;"><nobr style="line-height:1.2">TicketsClosedYesterday</nobr></td>
            <td class="csD4A184AD" style="width:104px;height:22px;text-align:left;vertical-align:top;"><nobr style="line-height:1.2">TicketsOpenedOn</nobr></td>
            <td class="csD4A184AD" style="width:210px;height:22px;text-align:left;vertical-align:top;"><nobr style="line-height:1.2">TicketsClosedYesterdaySLAViolations</nobr></td>
            <td class="csD4A184AD" style="width:172px;height:22px;text-align:left;vertical-align:top;"><nobr style="line-height:1.2">Dates</nobr></td>
        </tr>
        <tr style="vertical-align:top;">
            <td style="width:0px;height:22px;"></td>
            <td class="csD4A184AD" style="width:133px;height:22px;text-align:left;vertical-align:top;"><nobr style="line-height:1.2">646</nobr></td>
            <td class="csD4A184AD" style="width:104px;height:22px;text-align:left;vertical-align:top;"><nobr style="line-height:1.2">606</nobr></td>
            <td class="csD4A184AD" style="width:210px;height:22px;text-align:left;vertical-align:top;"><nobr style="line-height:1.2">141</nobr></td>
            <td class="csD4A184AD" style="width:172px;height:22px;text-align:left;vertical-align:top;"><nobr style="line-height:1.2">9/13/2016&nbsp;12:00:00&nbsp;AM</nobr></td>
        </tr>
    </table>

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    you refer to removing the first row, the first two <tr> and various numbers I can see in the first few rows and then refer to a whole bunch of code as the general gist of what you want gone.

    Can you be more specific - which is it?

  3. #3
    lonesoac0 is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Aug 2014
    Posts
    36
    I only want the following gone.

    <tr>
    <td style="width:0px;height:0px;"></td>
    <td style="height:0px;width:137px;"></td>
    <td style="height:0px;width:108px;"></td>
    <td style="height:0px;width:214px;"></td>
    <td style="height:0px;width:176px;"></td>
    </tr>

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    assuming your data is in a memo field, you should be able to use the replace function

    https://nortonsafe.search.ask.com/we...=en_GB&tpr=111

  5. #5
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    A little confusing for sure. You want ALL of what you posted gone? The first row of what you posted? The first table row? It would be dicey IMHO to rely on doing anything with the values you posted since (perhaps) other table cells that you want to keep could also become one of those values in the future, or it could be real data.
    Try this in a standard module to remove the first table row. You'll need to feed the function the html string and call it from your form (or whatever). You might have a variable there, such as strNewHtml, so you'd call it like:
    Code:
    strNewHtml = ParseTheHtml (string variable holding the original html goes here)
    
    Function ParseTheHtml(strHtml1 As String) As String
    Dim strHtml2 As String, strTarget As String
    Dim lngPos1 As Long, lngPos2 As Long
    
    lngPos1 = InStr(strHtml1, "<tr>")
    lngPos2 = InStr(strHtml1, "</tr>")
    strTarget = Mid(strHtml1, lngPos1, lngPos2 - lngPos1 + 5)
    strHtml2 = Replace(strHtml1, strTarget, "", 1)
    'Debug.Print strHtml2
    ParseTheHtml = strHtml2
    
    End Function
    EDIT:
    Took long enough to write this that I didn't see the new posts until I finished.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    an alternative to Micron's suggestion


    newHTMLstr=left(oldHTMLstr,instr("<tr>")-1) & mid(oldHTMLstr,instr("<\tr>")+6)
    Last edited by CJ_London; 09-15-2016 at 02:09 AM. Reason: correction to last value to exclude from the end of <\tr>

  7. #7
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    How is the report being generated? Is Access exporting the report as HTML?

  8. #8
    lonesoac0 is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Aug 2014
    Posts
    36
    Sorry for the confusion. A HTML report is being generated by a system called xtraction (http://www.xtractionsolutions.com/). I have attached a few HTML files that xtraction generates. I am trying to import the data into an access database. I have attached what is going on when I try to import the html data. It seems to be seeing one row that I do not see in my report designer by xtraction.
    Attached Thumbnails Attached Thumbnails Capture.GIF  
    Attached Files Attached Files

  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I am not familiar with that wizard. It looks similar to the older Import Wizard. Is there an option to Go Advanced? For instance, when importing a text file you have an option to exclude columns.

    Having said that, the wizard may be misinterpreting the HTML elements and improperly defining them. An alternative would be to use Access to automate Internet Explorer and parse the HTML tables via VBA.

  10. #10
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    .htm documents can be opened in a text editor, it should be pretty simple to remove the unwanted portions of your file using filesystemobject commands.

    If the formatting of the document is always the same the section you want to remove immediately follows the

    <table cell padding...

    line, then all you'd have to do is search for the first instance tr after that heading and re-write the file to a new file name excluding the unwanted rows. All that being said I think I'd be more inclined to do what itsme suggested and parse the actual table contents out of the HTML.

  11. #11
    lonesoac0 is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Aug 2014
    Posts
    36
    The first column is not the problem, because I can skip that in the advanced settings of the import. My issue is the first record. As you will note in the other screenshot below, when I mark the first row of headers the titles are not right. Access Marks them as just fields1,2,3 and 4, but I want them to be labeled: TicketsClosedYesterday, TicketsOpenedOn, TicketsClosedYesterdaySLAViolations, and Dates.
    Attached Thumbnails Attached Thumbnails Capture2.GIF   Capture3.GIF  

  12. #12
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Did you try either of the suggestions made by Itsme or me?

    1. Parsing the HTML with filesystemobject and pulling out the records
    2. Use filesystemobject to remove the section of HTML you don't want

  13. #13
    lonesoac0 is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Aug 2014
    Posts
    36
    This sounds like a winning suggestion. How can I parse the actual table contents out of the HTML with VBA?

  14. #14
    lonesoac0 is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Aug 2014
    Posts
    36
    You are replying too fast! lol I will try the filesystemobject method.

  15. #15
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Code:
    Dim fsDim sFileName
    Dim fIn
    Dim fOut
    
    
    Set fs = CreateObject("Scripting.filesystemobject")
    sFileName = "YesterdaysTicketStatsGeneratedToday - 201609140700.htm"
    Set fIn = fs.opentextfile(CurrentProject.Path & "\" & sFileName)
    Set fOut = fs.createtextfile(CurrentProject.Path & "\" & Replace(sFileName, ".htm", "_converted.htm"))
    
    
    Do While fIn.atendofstream <> True
        sline = fIn.readline
        fOut.writeline sline
        If InStr(sline, "<table cellpadd") > 0 Then
            Do Until InStr(sline, "</tr>") > 0
                sline = fIn.readline
            Loop
        End If
    Loop
    This code removes the section you want assuming the .htm files always follow the same format.

    If you want to parse the file and add records independently this is the method you'd use to read the file line by line, you'd just need to add code to recognize the lines that have data and pull them out based on positioning.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. How to use html tag <a>?
    By Corey in forum Modules
    Replies: 2
    Last Post: 08-10-2015, 02:17 PM
  2. HTML in VBA - faster way?
    By Ruegen in forum Programming
    Replies: 2
    Last Post: 12-11-2013, 08:52 PM
  3. HTML and VBA
    By tylerg11 in forum Forms
    Replies: 1
    Last Post: 08-23-2012, 05:53 PM
  4. ODBC Html
    By trenta7 in forum Import/Export Data
    Replies: 1
    Last Post: 02-08-2011, 08:55 AM
  5. HTML E-mail Using VBA
    By graviz in forum Programming
    Replies: 1
    Last Post: 12-09-2009, 08:52 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums