HTMLTableRow - cloneNode, replacing innerHTML resulting in missing <TD> ???

Posted on 2006-04-19
Last Modified: 2008-01-09
Iam trying to copy an original row with some tag information, then replace these tags with information from my database
The code below is actually working quite good however doing the newRow.innerHTML = newRow.innerHTML (should do nothing) results in the starting <TD> missing
Meaning you get a bad looking table
Does anyone know another way of doing this or what iam doing wrong ?
Additionally i would like a way to delete the originalRow from the html document...

        Dim originalRow As HTMLTableRow
        Dim newRow As HTMLTableRow
        Set originalRow = dd.getElementById("indLinie")
        salg_db.Open "SELECT * From betalinger", frmFront.registerCnxn, adOpenForwardOnly, adLockReadOnly
        While Not salg_db.EOF
            Set newRow = originalRow.cloneNode(True)
            If salg_db!type = 0 Then
                newRow.innerHTML = Replace(Replace(Replace(newRow.innerHTML, "[RegnNavn]", salg_db!tekst), "[RegnBelob]", FormatCurrency(salg_db!tal)), "[Type]", "Indb.")
                newRow.innerHTML = Replace(Replace(Replace(newRow.innerHTML, "[RegnNavn]", salg_db!tekst), "[RegnBelob]", FormatCurrency(salg_db!tal)), "[Type]", "Udb.")
            End If
            Call originalRow.appendChild(newRow)
Question by:mSchmidt
    LVL 8

    Accepted Solution

    LVL 17

    Expert Comment

    I've reproduced your problem and it's rather strange. I tried using the specific table functions from the link above and it did not help either, but maybe because I was missing some additional elements.

    This was what I managed and it may help you. A bit sloppy, I know.

        Dim o_doc As HTMLDocument
        Dim o_tbl As HTMLTable
        Dim o_row As HTMLTableRow
        Dim o_rowNew As HTMLTableRow
        Dim o_rowCell As HTMLTableCell
        'get initial elements
        Set o_doc = WebBrowser1.Document
        Set o_row = o_doc.getElementById("row1")
        Set o_tbl = o_row.parentElement.parentElement
        'create new row and cell
        Set o_rowNew = o_doc.createElement("tr")
        Set o_rowCell = o_doc.createElement("td")
        'assign content to the cell and append it to the row
        o_rowCell.innerHTML = "testing"
        Call o_rowNew.appendChild(o_rowCell)
        'insert the new row before the old one and remove the old one
        Call o_row.insertAdjacentElement("beforeBegin", o_rowNew)
        Call o_row.parentNode.removeChild(o_row)


    Author Comment

    I have managed to get it working using the following code.. it seems that innerHTML should only be used on HTMLTableCells

            Set originalRow = dd.getElementById("udLinie")
            For Each ahv In dDagsInfo.udbetalingCol
                Set newRow = originalRow.cloneNode(True)
                For Each newCell In newRow.childNodes
                    newCell.innerHTML = Replace(Replace(Replace(newCell.innerHTML, "[RegnNavn]", ahv.vareNavn), "[RegnBelob]", FormatCurrency(ahv.vareTotal)), "[Type]", "Indb.")
                Call originalRow.insertAdjacentElement("afterEnd", newRow)
            Call originalRow.parentElement.removeChild(originalRow)

    Thanks for you help though

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    759 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

    8 Experts available now in Live!

    Get 1:1 Help Now