Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195

    Where Am I Going Wrong!!!

    Hi Guy's, I have successfully, or very close to successfully tried to set HTML table vertically apart from unsure why the postcode is is not lined up in the correct place ?



    I have tried changing a few things such as line feeds (<br>) to bring it in line but can't seem to see why ?

    as always, much appreciated

    CustPC is next to signature see yellow highlight, it should be see blank yellow highlight

    Note: i have had to scribble out data for data protection reasons

    Code:
        iRec = Me.txtID    
        strSQL = "SELECT tblQuotations.ID, tblQuotations.QuoteDate, tblQuotations.Customer, tblQuotations.CustAdd1, tblQuotations.CustAdd2, tblQuotations.CustTown, tblQuotations.CustPC " _
                & "From tblQuotations " _
                & "WHERE (((tblQuotations.ID)= " & iRec & "));"
     
        Set rs = CurrentDb.OpenRecordset(strSQL)
                        
    strHTML = "<HTML><Body><table style='width:80%'>" & _
                        "<tr><th>Quote ID:</th><td>" & rs.Fields("ID") & "</td></tr>" & _
                        "<tr><th>Customer:</th><td>" & rs.Fields("Customer") & "</td></tr>" & _
                        "<tr><th>Address:</th><td>" & rs.Fields("CustAdd1") & "</td></tr>" & _
                        "<tr><th>Address:</th><td>" & rs.Fields("CustAdd2") & "</td></tr>" & _
                        "<tr><th>Town:</th><td>" & rs.Fields("CustTown") & "</td></tr>" & _
                        "<tr><th>PostCode:</th><td>" & rs.Fields("CustPC") & "</td></tr>"
    
                        
        strBody = strHTML
        
        sFH = "<font size='4' face='Verdana' style=text-align=center; vertical-align=middle>"
        sFHEnd = "</font>"
        
        Set myItem = myApp.CreateItem(olMailItem)
        Set OutAccount = myApp.Session.Accounts.Item(1)
        With myItem
            .To = strEmail
            .subject = Me.cboCustomer & " Quotation"
            .HTMLBody = strFS & myGreet & strFE & "<br>" & "<br>" & _
            strFS & strBody & strFE & "<br>" & "<br>" & _
            "<br>" & strUserSign & "<br>" & "<br>" & _
            "<P><IMG border=0 hspace=0 alt='' src='file://T:/DMT Ltd/Logo Media/" & SigFile & "' align=baseline></P>" & "<br>" & "<br>" & _
            "<FONT color=#00008B>" & eDisc & "<br>" & "<FONT color =#00008B>" & eDisc2
            .SendUsingAccount = OutAccount
            .Display
        End With
    
    
    Set rs = Nothing
    Click image for larger version. 

Name:	Capture.JPG 
Views:	34 
Size:	27.6 KB 
ID:	50260

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    A few things spring to mind

    strFS and strFE I can't see defined anywhere, so no idea what they contain.

    However you probably need to close your HTML table, so that things don't get muddled up. Try putting

    </table>

    at the end of your initial table formatting
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi Minty, strFS and strFE (font start and font end is a string set to change the font details when needed

    Yes i will try that, as an after though, i knew the table was not terminated so will do that

    Also, now that i have the html table with vertical headers, how do i add them to cells (like excel/datasheet) based on my HTML string ?

    Kindest

  4. #4
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Code:
    strFS = "<font size='3' face='Arial' style=text-align=center; vertical-align=middle>"    strFE = "</font>"
        sSmiley = "<span style='font-size:16px;'>😄</span>"

  5. #5
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    You are also assigning a row to each header, it should look like this:
    Code:
    <tr>
      <th>header1</th>
      <th>header2</th>
    </tr>
    <tr>
      <td>cell1</td>
      <td>cell2</td>
    </tr>
    And yours looks like this:
    Code:
    <tr>
      <th>header1</th>
      <td>cell1</td>
    </tr>
    <tr>
      <th>header2</th>
      <td>cell2</td>
    </tr>
    EDIT:
    I just read you actually wanted it that way. How exactly do you need this to look?

  6. #6
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi Edgar, thank you, exactly as original post, instead of horizontal header, have vertical header, that was achieved but inside inside cells, hope this explains

    i have looked at HTML School online but can't appear to adapt it at the moment, i guess i could spend a lot of time going the hard way about it hence asking

    Same as image in post 1 but each header and data in their own cells like this

    Click image for larger version. 

Name:	Capture.JPG 
Views:	28 
Size:	22.0 KB 
ID:	50263

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    You want this to look like a table of cells with borders? Example:
    Code:
    Dim strS As String, strT As String
    strS = "width='500' style='text-align:left;border:2px;font-family:calibri;border-collapse:collapse;padding:5px'"
    strT = "style='border:3px solid black' width='50%'"
    testH = "<table " & strS & "><tr><th " & strT & ">Initial quote : </th><td " & strT & "></td></tr>" & _
    "<tr><th " & strT & ">Discount rate : </th><td  " & strT & "></td></tr>" & _
    "<tr><th " & strT & ">Final quote : </th><td " & strT & "></td></tr></table><br>" & _
    "<table " & strS & "><tr><th " & strT & ">Last spend on year 2020 : </th><td " & strT & "></td></tr>" & _
    "<tr><th " & strT & ">Increment increase percentage : </th><td " & strT & "></td></tr>" & _
    "<tr><th " & strT & ">Final quote : </th><td " & strT & "></td></tr></table>"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    Code:
                strHTML = "<HTML><head><style>" & _
                         "table{border-collapse:collapse; width: 80%} td,th{text-align:left}  table,td,th{border: 1px solid black;}" & _
                        "</style></head><Body><table>" & _
                         "<tr><th>Quote ID:</th><td>" &  rst.Fields("ID") & "</td></tr>" & _
                         "<tr><th>Customer:</th><td>" &  rst.Fields("Customer") & "</td></tr>" & _
                         "<tr><th>Address:</th><td>" &  rst.Fields("CustAdd1") & "</td></tr>" & _
                         "<tr><th>Address:</th><td>" &  rst.Fields("CustAdd2") & "</td></tr>" & _
                         "<tr><th>Town:</th><td>" &  rst.Fields("CustTown") & "</td></tr>" & _
                         "<tr><th>PostCode:</th><td>" &  rst.Fields("CustPC") & "</td></tr>" & _
                        "</table>"
    This should do it, but there are a lot of other things you can do to adapt this code and make it more maintainable. I suspect you could do this with vba objects instead of relying so much in string manipulation, it would look much neater.

  9. #9
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Thanks June7 and Edgar, points taken and i am going to try both suggestions, Comment mine out so i can see the differences and where what i should be doing

  10. #10
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Quote Originally Posted by Edgar View Post
    I suspect you could do this with vba objects instead of relying so much in string manipulation
    I'd be curious to learn more about this if you could elaborate

  11. #11
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi Guy's i have used Edgars version which works very well, just now playing with borders and width's etc

    Thanks you again guy's, i can see the table/head setting difference compared to what i didn't have at all!!!!

    Code:
    iRec = Me.txtID    
        strSQL = "SELECT tblQuotations.ID, tblQuotations.QuoteDate, tblQuotations.Customer, tblQuotations.CustAdd1, tblQuotations.CustAdd2, tblQuotations.CustTown, tblQuotations.CustPC " _
                & "From tblQuotations " _
                & "WHERE (((tblQuotations.ID)= " & iRec & "));"
     
        Set rs = CurrentDb.OpenRecordset(strSQL)
    
    
            strHTML = "<HTML><head><style>" & _
                         "table{border-collapse:collapse; width: auto} td,th{text-align:left}  table,td,th{border: 2px solid blue;}" & _
                        "</style></head><Body><table>" & _
                            "<tr><th>Quote ID:</th><td>" & rs.Fields("ID") & "</td></tr>" & _
                            "<tr><th>Customer:</th><td>" & rs.Fields("Customer") & "</td></tr>" & _
                            "<tr><th>Address:</th><td>" & rs.Fields("CustAdd1") & "</td></tr>" & _
                            "<tr><th>Address:</th><td>" & rs.Fields("CustAdd2") & "</td></tr>" & _
                            "<tr><th>Town:</th><td>" & rs.Fields("CustTown") & "</td></tr>" & _
                            "<tr><th>PostCode:</th><td>" & rs.Fields("CustPC") & "</td></tr>" & _
                        "</table>"
    
    
        strBody = strHTML
        
        sFH = "<font size='4' face='Verdana' style=text-align=center; vertical-align=middle>"
        sFHEnd = "</font>"
        
        Set myItem = myApp.CreateItem(olMailItem)
        Set OutAccount = myApp.Session.Accounts.Item(1)
        With myItem
            .To = strEmail
            .subject = Me.cboCustomer & " Quotation"
            .HTMLBody = strFS & myGreet & strFE & "<br>" & "<br>" & _
            strFS & Replace(strBody, "|", "<br>") & strFE & "<br>" & "<br>" & _
            "<br>" & strUserSign & "<br>" & "<br>" & _
            "<P><IMG border=0 hspace=0 alt='' src='file://T:/DMT Ltd/Logo Media/" & SigFile & "' align=baseline></P>" & "<br>" & "<br>" & _
            "<FONT color=#00008B>" & eDisc & "<br>" & "<FONT color =#00008B>" & eDisc2
            .SendUsingAccount = OutAccount
            .Display
        End With
    
    
    Set rs = Nothing

    Click image for larger version. 

Name:	Capture.JPG 
Views:	25 
Size:	23.5 KB 
ID:	50265

  12. #12
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    Quote Originally Posted by kd2017 View Post
    I'd be curious to learn more about this if you could elaborate
    Sure, I don't have outlook installed I'm using the browser control, but look at this code:
    Code:
    Option Compare Database
    Option Explicit
    
    Private doc As Object, head As Object, body As Object, _
    table As Object, tr As Object, th As Object, td As Object
    
    Private Sub btnAddTable_Click()
        Dim row As Long, col As Long
        Set table = doc.createElement("table")
        table.Style.Width = "100%"
        table.Style.borderCollapse = "collapse"
        table.Style.margin = "5px"
        body.appendChild table
        
        ' Create the table rows and columns
        For row = 1 To 2
            Set tr = doc.createElement("tr")
            table.appendChild tr
            
            For col = 1 To 3
                Set td = doc.createElement("td")
                td.innerText = "Row " & row & ", Column " & col
                td.Style.border = "1px solid f2f2f2"
                td.Style.backgroundColor = "c5c5c5"
                td.Style.Color = "333"
                tr.appendChild td
            Next col
        Next row
        
        ' Display the HTML output
        Me.txtOutput = doc.documentElement.outerHTML
    End Sub
    
    Private Sub btnHtmlDoc_Click()
        Me.txtOutput = doc.documentElement.outerHTML
    End Sub
    
    Private Sub Form_Open(Cancel As Integer)
        Me.WebBrowser0.ControlSource = "=""about:blank"""
    End Sub
    
    Private Sub WebBrowser0_DocumentComplete(ByVal pDisp As Object, URL As Variant)
        If Me.WebBrowser0.ReadyState = acComplete Then
            Set doc = Me.WebBrowser0.Object.Document
            Set head = doc.head
            Set body = doc.body
        End If
    End Sub
    As you can see, since it's the browser control, first I set it to a blank page to obtain a blank document. Once the browser is fully loaded, it sets the doc variable to the browser's automation document and also gets the head and the body because when a document starts, it comes like this: <html><head></head><body></body></html>. Then, with the buttons we can perform actions on the browser using the doc variable previously set.

    I'm basically creating the same table whenever I click and the html code is shown in the textbox. To create the elements it's just a matter of appending children to the parent element. That takes care of the opening and closing of tags. And you can see I'm also adding attributes.

    This works with Access 2016, it may not be the same for other versions, because they're constantly changing things, but I hope you get the idea. If you're going to build an email, it's just a matter of creating the document, automating it and then outputting the html to the .HTMLBody property of it, as OP shows in his code. But take a look at the properties of the email, maybe there's a way to attach the object itself instead of the innerHTML text. Either way, it should work.

    I'm using a late bound method but you can add a reference to Microsoft HTML Object Library to work with intellisense.
    Attached Files Attached Files

  13. #13
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    I think we aren't closing the body or the html either, my bad, it's good that it works though. You can still get rid of the font tag changing it for a <p> tag and add the styling between the <style> tags

  14. #14
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Quote Originally Posted by Edgar View Post
    Sure, I don't have outlook installed I'm using the browser control, but look at this code:
    Code:
    Option Compare Database
    Option Explicit
    
    Private doc As Object, head As Object, body As Object, _
    table As Object, tr As Object, th As Object, td As Object
    
    Private Sub btnAddTable_Click()
        Dim row As Long, col As Long
        Set table = doc.createElement("table")
        table.Style.Width = "100%"
        table.Style.borderCollapse = "collapse"
        table.Style.margin = "5px"
        body.appendChild table
        
        ' Create the table rows and columns
        For row = 1 To 2
            Set tr = doc.createElement("tr")
            table.appendChild tr
            
            For col = 1 To 3
                Set td = doc.createElement("td")
                td.innerText = "Row " & row & ", Column " & col
                td.Style.border = "1px solid f2f2f2"
                td.Style.backgroundColor = "c5c5c5"
                td.Style.Color = "333"
                tr.appendChild td
            Next col
        Next row
        
        ' Display the HTML output
        Me.txtOutput = doc.documentElement.outerHTML
    End Sub
    
    Private Sub btnHtmlDoc_Click()
        Me.txtOutput = doc.documentElement.outerHTML
    End Sub
    
    Private Sub Form_Open(Cancel As Integer)
        Me.WebBrowser0.ControlSource = "=""about:blank"""
    End Sub
    
    Private Sub WebBrowser0_DocumentComplete(ByVal pDisp As Object, URL As Variant)
        If Me.WebBrowser0.ReadyState = acComplete Then
            Set doc = Me.WebBrowser0.Object.Document
            Set head = doc.head
            Set body = doc.body
        End If
    End Sub
    As you can see, since it's the browser control, first I set it to a blank page to obtain a blank document. Once the browser is fully loaded, it sets the doc variable to the browser's automation document and also gets the head and the body because when a document starts, it comes like this: <html><head></head><body></body></html>. Then, with the buttons we can perform actions on the browser using the doc variable previously set.

    I'm basically creating the same table whenever I click and the html code is shown in the textbox. To create the elements it's just a matter of appending children to the parent element. That takes care of the opening and closing of tags. And you can see I'm also adding attributes.

    This works with Access 2016, it may not be the same for other versions, because they're constantly changing things, but I hope you get the idea. If you're going to build an email, it's just a matter of creating the document, automating it and then outputting the html to the .HTMLBody property of it, as OP shows in his code. But take a look at the properties of the email, maybe there's a way to attach the object itself instead of the innerHTML text. Either way, it should work.

    I'm using a late bound method but you can add a reference to Microsoft HTML Object Library to work with intellisense.

    Neat! Since using a web control would be a little inconvenient I prompted chatgpt do write something similar for outlook and it used the 'Microsoft HTML Object Library'. I wasn't familiar with this! But... at the end of the day it's just looks simpler to me to just build a html string for this particular use case.

  15. #15
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    Quote Originally Posted by kd2017 View Post
    Neat! Since using a web control would be a little inconvenient I prompted chatgpt do write something similar for outlook and it used the 'Microsoft HTML Object Library'. I wasn't familiar with this! But... at the end of the day it's just looks simpler to me to just build a html string for this particular use case.
    Yes, it is very simple. I used the browser control just for demonstration, to have somehting to show, but you should be able to create the html document without any control, with pure vba. Do take into account that we're adding style attributes to each tag with this approach, it would be even better to use classes for the styling. That approach is a little tricky, but it is also possible. It would involve creating the style tags and appending them to the head. Once you have them, you can use something like this:
    Code:
    Private Sub StyleText()
        ruleIndex = styles.sheet.addRule(".name", " ")
        With styles.sheet.rules.Item(ruleIndex).style
            .FontFamily = "calibri, arial" 'main font, fallback
            .marginTop = "10px" 'add margin between image and text
            .display = "block" 'center text
            .TextAlign = "center" 'center text
            .textDecoration = "none" 'remove underline
            .Color = "000" 'black text
        End With
    End Sub
    This way, you have a stylesheet doing the styling and your tags will look much cleaner.

    So, did the output from chatgpt work for your case?

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

Similar Threads

  1. what the ##$$$$$$@@!! am i not see or doing wrong??
    By Synergy.ron@gmail.com in forum Programming
    Replies: 6
    Last Post: 08-08-2021, 09:30 AM
  2. what is wrong ?
    By dino in forum Access
    Replies: 19
    Last Post: 07-29-2015, 11:13 AM
  3. What am I doing wrong?
    By Access_noob_ in forum Programming
    Replies: 3
    Last Post: 11-03-2014, 10:47 AM
  4. VBA gone wrong with an if
    By Ruegen in forum Programming
    Replies: 2
    Last Post: 10-21-2013, 05:38 PM
  5. What's wrong!
    By khalid in forum Programming
    Replies: 15
    Last Post: 06-27-2011, 06:38 AM

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