Results 1 to 7 of 7
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195

    Aligning Each Field Equally

    Hi Guys, I have successfully written some code that will out put total and average costings between selected periods, all works great, the only additional finishing (tidy up) would be to align the fields with the next line, how can this be done please ?



    Note: i have not put the full code on as its quite long and not as if it's not working because it is, it's just a question of alignment

    Currently the result is something like:

    a a a a a a a
    b b b b b b b
    c c c c c c c c

    whereas i would like to align:

    a a a a a a a
    b b b b b b b
    c c c c c c c

    etc

    I have no doubt its because of the length of field results ie: more characters in December than June and different results making various length for each line

    If there is a method to align all regardless of field length would be fab ?

    i am already adding 4 spaces by replacing "AddSpace"

    Code:
    strBoxS = "<table style='text-align:left;border:3px solid black;font-family:Arial;border-collapse:collapse;padding:25px'><th>" & "FUEL PRICES" & "</th><tr style='background:white;mso-highlight:blue'>"strMarkS = "<span style='background:yellow'>"
    strMarkE = "</span>"
    strBoxE = "</tr></table>"
    strFontS = "<font size='3'>"
    strFontE = "</font>"
    
    
    If lYearStart < lYearEnd Then
        strTitle = "Fuel Prices Between " & lYearStart & " And " & lYearEnd & "|"
        strSubj = "Fuel Prices Between " & lYearStart & " And " & lYearEnd
        strSQL = "SELECT tblExpenses.ItemRequired, tblExpenses.Year, tblExpenses.MonthNo, Sum(tblExpenses.TotalAmount) AS SumOfTotalAmount, Sum(tblExpenses.Litres) AS SumOfLitres, " _
            & "Avg(tblExpenses.PricePerLitre) AS AvgOfPricePerLitre " _
            & "From tblExpenses " _
            & "GROUP BY tblExpenses.ItemRequired, tblExpenses.Year, tblExpenses.MonthNo " _
            & "HAVING (((tblExpenses.ItemRequired) = '" & strItem & "') AND ((tblExpenses.Year) Between " & lYearStart & " And " & lYearEnd & ")) " _
            & "ORDER BY Avg(tblExpenses.PricePerLitre) DESC;"
            
        Set rs = CurrentDb.OpenRecordset(strSQL)
        Do Until rs.EOF
            If rs.Fields("MonthNo") = MonthNow Then
            strMonth = "<span style='background:yellow'>" & MonthName(rs.Fields("MonthNo")) & "</span>"
            End If
            If rs.Fields("MonthNo") <> MonthNow Then
            strMonth = MonthName(rs.Fields("MonthNo"))
            End If
            
            strBody = strBody & rs.Fields("ItemRequired") & "AddSpace" & strMonth & " " & rs.Fields("Year") & _
            "AddSpace" & Format(rs.Fields("SumOfTotalAmount"), "Currency") & _
            "AddSpace" & "Litres: " & rs.Fields("SumOfLitres") & "AddSpace" & "PPL " & Format(rs.Fields("AvgOfPricePerLitre"), "Currency") & "|"
            
            rs.MoveNext
        Loop
            Set olItem = olApp.CreateItem(olMailItem)
            Set olAccount = olApp.Session.Accounts.Item(1)
            With olItem
            .To = strMailTo
            .subject = strSubj
            .HTMLBody = "<br>" & strBoxS & strFontS & "<br>" & Replace(strTitle, "|", "<br>" & "<br>") & "<br>" & Replace(Replace(strBody, "|", "<br>"), "AddSpace", "&emsp;") & strFontE & strBoxE
            .SendUsingAccount = olAccount
            .Display
            End With
    End If

  2. #2
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Once posted by alignment of a, b and c doesn't look right on here but its sporadic alignment due to field data length whereas i am trying line vertically

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    what does your addspace function actually do? i.e. what character is it adding? - if chr(32) that won't work with html, you need to use &nbsp or a variation.

    see this link
    https://stackoverflow.com/questions/...ng-spaces-nbsp

    personally would think adding a table would be the way forward - also in the above link

  4. #4
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi Ajax, the "AddSpace" is just to replace with &emsp (4 spaces)

    this line does do the spaces:

    .HTMLBody = "<br>" & strBoxS & strFontS & "<br>" & Replace(strTitle, "|", "<br>" & "<br>") & "<br>" & Replace(Replace(strBody, "|", "<br>"), "AddSpace", "&emsp;") & strFontE & strBoxE
    AddSpace is not a field or function, its purely my own words to add space because initially i used "sp" my own insert for something to replace, wasn't good because the word span is in there so its my own word so i can use in html the &emsp

    That all works and creates 4 spaces as &emsp should so, i was trying align the next record (<br>)

    Perhaps how do I change my table to what would be a data sheet and i guess that would do the trick as each box (cell) in the table would be field records then next record would be directly under in a cell ????

    Would that do it and how do i do it if so ???

    Kindest

  5. #5
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    The records are in the table see strBoxS (Start Table)

  6. #6
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Your examples before and required look the same to me.

    If you are putting in a table then you shouldn't need your addspace. Plus emps is not always recognised any - depends on the version of html. No idea if it works or not with outlook. suggest try my suggestion

    Don't see how you are implementing and populating the table, I would expect to see <td> and </td>tags around each cell of the table

  7. #7
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Thanks Ajax, will adjust to your suggestion, again many thanks

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Aligning Tick Boxes With Labels
    By Chris Waller in forum Forms
    Replies: 8
    Last Post: 10-20-2014, 02:29 AM
  2. Aligning things in ms access
    By oly in forum Access
    Replies: 2
    Last Post: 02-22-2013, 12:49 PM
  3. Distributing Records Equally by Value
    By JerBearMO in forum Programming
    Replies: 3
    Last Post: 02-26-2012, 03:09 PM
  4. Aligning email message text when using SendObject
    By msoares in forum Programming
    Replies: 1
    Last Post: 02-15-2011, 07:22 AM
  5. Aligning a string vertically
    By Divardo in forum Queries
    Replies: 3
    Last Post: 06-10-2009, 11:19 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