Bold MsgBox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PhilOfWalton
    Recognized Expert Top Contributor
    • Mar 2016
    • 1430

    Bold MsgBox

    Been struggling with this all evening.

    I want to pass values to a Msgbox, and have some lines in bold font, and others in normal font.

    I know if I type the 2 messages in in full, it works, but I want to pass the strings.

    This is what it looks like:-

    As you see the Bold bit is working, but I can't get "his is a normal message" to print

    Code below
    Code:
    Option Compare Database
    Option Explicit
    
    Function TestBoldMsgBox()
    
        Dim MsgBold As String
        Dim MsgNormal As String
        
        MsgBold = "This is a Bold Message"
        MsgNormal = "This is a  Normal Message"
                        
        Debug.Print Eval("MsgBox ('" & MsgBold & vbNewLine _
        & "@msgnormal@@', " & vbOKOnly & ", 'Testing Bold')")
                        
    End Function
    What am I doing wrong?

    Thanks

    Phil
    Attached Files
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3653

    #2
    Phil,

    You forgot to treat your variable as a variable:

    Code:
    Option Compare Database
    Option Explicit
     
    Public Function TestBoldMsgBox()
     
        Dim MsgBold As String
        Dim MsgNormal As String
     
        MsgBold = "This is a Bold Message"
        MsgNormal = "This is a  Normal Message"
     
        Debug.Print Eval("MsgBox ('" & MsgBold & vbNewLine _
        & "@" & MsgNormal & "@@', " & vbOKOnly & ", 'Testing Bold')")
     
    End Function
    Although, I have absolutely no clue as to why this makes bold and normal text.
    Last edited by twinnyfo; Oct 22 '18, 10:47 PM.

    Comment

    • PhilOfWalton
      Recognized Expert Top Contributor
      • Mar 2016
      • 1430

      #3
      So simple

      It just takes a genius to show me the way

      Grateful thanks

      Phil

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32636

        #4
        Hi Twinny.

        I didn't know either so I did a bit of digging and found that the VBA version of MsgBox() doesn't handle that. Only the Access (or Expression Service) version does. IE. The one used by SQL and other expressions. That's why the Eval() is used. That works with the Expression Service and has no real access to the VBA library - even though many functions are similar to VBA ones.

        In that old version ats (@s) are treated as line separators and only the first line is bold. I believe that two ats are required for this to be recognised and at least one space required after the third. If you want multiple lines in bold then insert one of the line separator constants (or equivalents - VbCrLf, VbNewLine, VbCr or VbLf) before the first @.

        I only repeat what I've gleaned from posts others have made so can't confirm. Have a play and test out the limits for yourself.

        PS. That's why Phil's use of the single quotes works BTW.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32636

          #5
          You'll also notice that using an @ as well as a VbNewLine gives two line breaks - which is not correct.

          See earlier post for full explanation including why that is ;-)

          Comment

          Working...