XP Style Msgbox Buttons (1 Viewer)

meanster99

Meum cerebrum nocet!
Local time
Today, 15:14
Joined
May 2, 2006
Messages
62
Hi guys,

I have searched for an hour now but to no avail! Can anyone tell me how I enable the XP style for my Msgbox buttons? Any command buttons I create on forms are in the XP style but when I use Msgbox in VBA they appear in the old flat (ugly) style.

It must be a simple thing to do - I read about manifest files but surely there is an easier way?

Thanks in advance...
 
Last edited:

wazz

Super Moderator
Local time
Today, 22:14
Joined
Jun 29, 2004
Messages
1,711
possibly:

control panel > display > appearance tab > windows and buttons
 

meanster99

Meum cerebrum nocet!
Local time
Today, 15:14
Joined
May 2, 2006
Messages
62
Unfortunately not Wazz. It makes no sense to me - why is it only when I use msgbox in vba that the OK/Yes/No/cancel buttons appear in the old flat style.

However, the following code displays a msgbox that does have the XP style buttons, even though if I just use msgbox and not the Eval expression I get the old flat styles still!

Code:
Eval ("MsgBox ('Your Bold Text Here.@Your Normal Text Here.@@',52,'Your Title Here')")

The problem (for me) with using these Eval statements is knowing what argument numbers to use to display the correct sort of vb msgbox (you have to use trial and error), aswell as me not knowing how to include field values in these statements (I know how to do it in a normal msgbox statement but couldn't get it to work with this Eval statement)

Surely someone must have a solution to this or can point me in the right direction?
 

dcb

Normally Lost
Local time
Today, 16:14
Joined
Sep 15, 2009
Messages
529
Give this a try (built a function on your code below)

Code:
Public Function dMsgBox( _
    ByVal mTitle As String, _
    ByVal mType As Long, _
    Optional ByVal mBold As String, _
    Optional ByVal mNormal As String) _
    As Integer
      '---------------------------------------------------------------------------------------
      ' Procedure : dMsgBox
      ' Author    : DCB
      ' Date      : 19/10/2009
      ' Purpose   : Styled MsgBox
      ' Return    : Integer as per normal VBA MsgBox Constants
      '           :
      ' Inputs    : mNormal   -> Normal Text
      '           : mBold     -> Bold Text
      '           : mTitle    -> MsgBox Title
      '           : mType     -> Sum of vbConstants for MsgBox
      '---------------------------------------------------------------------------------------
      '
    Dim strMsgBox As String
    If mNormal = "" Then mNormal = " "
    strMsgBox = "MsgBox ('" & mBold & "@" & mNormal & "@@'," & mType & ", '" & mTitle & "')"
    dMsgBox = Eval(strMsgBox)
 
End Function

To work out the argument numbers Sum the constants:
PHP:
'    MsgBox Constants       ''From help File
'        Constant               Value   Description
'   Buttons
'        vbOKOnly               0       Display OK button only.
'        vbOKCancel             1       Display OK and Cancel buttons.
'        vbAbortRetryIgnore     2       Display Abort, Retry, and Ignore buttons.
'        vbYesNoCancel          3       Display Yes, No, and Cancel buttons.
'        vbYesNo                4       Display Yes and No buttons.
'        vbRetryCancel          5       Display Retry and Cancel buttons.
'   Icons
'        vbCritical             16      Display Critical Message icon.
'        vbQuestion             32      Display Warning Query icon.
'        vbExclamation          48      Display Warning Message icon.
'        vbInformation          64      Display Information Message icon.
'   Defaults
'        vbDefaultButton1       0       First button is default.
'        vbDefaultButton2       256     Second button is default.
'        vbDefaultButton3       512     Third button is default.
'        vbDefaultButton4       768     Fourth button is default.
'   Application
'        vbApplicationModal     0       Application modal; the user must respond to the message box before continuing work in the current application.
'        vbSystemModal          4096    System modal; all applications are suspended until the user responds to the message box.
'        vbMsgBoxHelpButton     16384   Adds Help button to the message box.
'        VbMsgBoxSetForeground  65536   Specifies the message box window as the foreground window.
'        vbMsgBoxRight          524288  Text is right aligned.
'        vbMsgBoxRtlReading     1048576 Specifies text should appear as right-to-left reading on Hebrew and Arabic systems.

As for why the MsgBox loses the style ----- Who knows!
 

meanster99

Meum cerebrum nocet!
Local time
Today, 15:14
Joined
May 2, 2006
Messages
62
Hi dcb

Many thanks for taking the time to write this function. I can sort of see what it is doing but I am a complete noob with vba and I dont know whether this goes in a module or in a form and how I actually use it!

Any pointers would be greatly appreciated!
 

wazz

Super Moderator
Local time
Today, 22:14
Joined
Jun 29, 2004
Messages
1,711
in vba editor go:
insert > module

copy everything dcb posted (both code blocks) into the module. save the module, name it whatever you want, you can rename it later.

in any form's code module, enter this next part by hand (type it in so you can see how it works):

dMsgBox "title", 64, "bold", "normal"

the 64 can be anything you want by adding different constant values together.
' vbInformation 64 Display Information Message icon.

if you want the info icon and 'yes/no' buttons, change 64 to 68 (64+4).
 

DCrake

Remembered
Local time
Today, 15:14
Joined
Jun 8, 2005
Messages
8,626
When Access moved from VBE to VBA it removed the Formatted message box. ie using the @ symbols to delimit the string between bold and normal text was VBE. So if you then upgraded to 2003 all you got was a long string with @'s in it.

There is a eval equivelant post above that replaces the normal msgbox. A different version is shown below.

Code:
Function FMsgBox(Prompt As String, _
                         Optional Buttons As VbMsgBoxStyle = vbOKOnly, _
                         Optional TITLE As String = "PPE Limited", _
                         Optional HelpFile As Variant, _
                         Optional Context As Variant) As VbMsgBoxResult
    

    Dim strMsg As String
    If IsMissing(HelpFile) Or IsMissing(Context) Then
       strMsg = "MsgBox(" & Chr(34) & Prompt & Chr(34) & ", " & Buttons & _
                 ", " & Chr(34) & TITLE & Chr(34) & ")"
    Else
       strMsg = "MsgBox(" & Chr(34) & Prompt & Chr(34) & ", " & Buttons & _
                 ", " & Chr(34) & TITLE & Chr(34) & ", " & Chr(34) & _
                      HelpFile & Chr(34) & ", " & Context & ")"
    End If
    FMsgBox = Eval(strMsg)
End Function

Example of usage

Code:
        Call FMsgBox("Cannot perform save at this time@At least one entry is invalid or is missing. Please revise and retry.@Click Ok to continue.", vbExclamation + vbOKOnly, "Subscriptions")

David
 

dcb

Normally Lost
Local time
Today, 16:14
Joined
Sep 15, 2009
Messages
529
Code:
Optional Buttons As VbMsgBoxStyle = vbOKOnly
Nice - hadnt thought of that!
 

meanster99

Meum cerebrum nocet!
Local time
Today, 15:14
Joined
May 2, 2006
Messages
62
Thanks guys.

Wazz - thats excatly what I had tried but I get the error message:

expected variable or procedure, not module

DCrake - I can call your function and it works as it should but is it possible to include field values in the msgbox like I do below with ordinary msgbox statements:

Code:
If MsgBox("Changes have been made to the record for: " _
    & vbCrLf & vbCrLf & Me.Title & ". " & Me.Forename & " " & Me.Surname _
    & vbCrLf & vbCrLf & "Do you want to save these changes?" _
    , vbYesNo + vbQuestion, "Confirm Changes") = vbYes Then
    DoCmd.Save
Else
    DoCmd.RunCommand acCmdUndo
End If
End Sub

I'm not even really looking to make one line bold (bonus though that I can), the principal aim was to give all my msgboxes the XP style buttons which they currently all lack in vba when using the standard msgbox statement. Its an aesthetic point really and one I shouldn't be that bothered about but now I have it in my head to solve it I can't let it lie!
 

dcb

Normally Lost
Local time
Today, 16:14
Joined
Sep 15, 2009
Messages
529
Hi

You need the "Call" on the front - same as DCrake
Last example below:
Code:
Public Sub testf()
    Debug.Print dMsgBox("Title", 65, "Bold", "Normal")
    Debug.Print dMsgBox("Title", 65, , "Normal")
    Debug.Print dMsgBox("Title", 65, "Bold")
    Call dMsgBox("Title", 65, "Bold")       ''This does not use the return
End Sub
 

meanster99

Meum cerebrum nocet!
Local time
Today, 15:14
Joined
May 2, 2006
Messages
62
Thanks dcb - I did use call but didn't use the brackets as I should have done which is why it didnt work.

I have tried playing about with the dmsgbox and fmsgbox functions dcb and CDrake gave me to include the field names I need to display but I can't get them to appear where I want them.

Any suggestions?
 

dcb

Normally Lost
Local time
Today, 16:14
Joined
Sep 15, 2009
Messages
529
Just tested this:
Code:
    If dMsgBox("David", vbYesNo, , Me.TVTopName & vbCrLf & Me.TVTopDetail) = vbYes Then Debug.Print "Yes"
That what your looking to do?
 

meanster99

Meum cerebrum nocet!
Local time
Today, 15:14
Joined
May 2, 2006
Messages
62
Strangely, that doesn't work for me. I am using your original Msgbox function you provided for me.

I am looking to create the same message box as the code below produces but using your function so that I get the xp style buttons:

Code:
If MsgBox("Changes have been made to the record for: " _
    & vbCrLf & vbCrLf & Me.Title & ". " & Me.Forename & " " & Me.Surname _
    & vbCrLf & vbCrLf & "Do you want to save these changes?" _
    , vbYesNo + vbQuestion, "Confirm Changes") = vbYes Then
    DoCmd.Save
Else
    DoCmd.RunCommand acCmdUndo
End If
End Sub

Where the field names are:

Title
Forename
Surname

Your function:
Code:
Public Function dMsgbox( _
    ByVal mTitle As String, _
    ByVal mType As Long, _
    Optional ByVal mBold As String, _
    Optional ByVal mNormal As String) _
    As Integer
      '---------------------------------------------------------------------------------------
      ' Procedure : dMsgBox
      ' Author    : DCB
      ' Date      : 19/10/2009
      ' Purpose   : Styled MsgBox
      ' Return    : Integer as per normal VBA MsgBox Constants
      '           :
      ' Inputs    : mNormal   -> Normal Text
      '           : mBold     -> Bold Text
      '           : mTitle    -> MsgBox Title
      '           : mType     -> Sum of vbConstants for MsgBox
      '---------------------------------------------------------------------------------------
      '
    Dim strMsgBox As String
    If mNormal = "" Then mNormal = " "
    strMsgBox = "MsgBox ('" & mBold & "@" & mNormal & "@@'," & mType & ", '" & mTitle & "')"
    dMsgbox = Eval(strMsgBox)
 
End Function
 

dcb

Normally Lost
Local time
Today, 16:14
Joined
Sep 15, 2009
Messages
529
Code:
    If dMsgBox("Confirm Changes?", vbYesNo + vbQuestion, , "Changes have been made to the record for: " _
        & vbCrLf & vbCrLf & Me.TITLE & ". " & Me.Forename & " " & Me.Surname _
        & vbCrLf & vbCrLf & "Do you want to save these changes?") = vbYes Then
            ''CODE
    Else
            ''CODE
    End If
 

meanster99

Meum cerebrum nocet!
Local time
Today, 15:14
Joined
May 2, 2006
Messages
62
Thanks dcb thats exactly it! You are a legend.

The only shortcoming it has at the moment is that it only works if I put the function in the form rather than have it as a public function in a module. If I have it in a module I get the error message :

expected variable or procedure, not module

Any ideas? Thanks for all your help upto now (and the other contributors).
 

dcb

Normally Lost
Local time
Today, 16:14
Joined
Sep 15, 2009
Messages
529
Hi

Post your code you are trying to call it with - let me have a look
The code I posted was using it as a function in a module
 

meanster99

Meum cerebrum nocet!
Local time
Today, 15:14
Joined
May 2, 2006
Messages
62
Hi dcb - I have worked out what the problem was - my stupidity! I had named the module dMsgbox aswell as the function which was causing the compile error.

Many thanks for all your help with this. It took a while I know, but you perservered with me. Lekker!
 

namliam

The Mailman - AWF VIP
Local time
Today, 16:14
Joined
Aug 11, 2003
Messages
11,695
I had named the module dMsgbox aswell as the function which was causing the compile error.
Learn this lesson now and here, prefix everything as to what it is to prevent this error in the future... Not only functions but any object
qry
tbl
mdl
fn
mcr
rpt
sub
int
dbl
dt
txt
cbo
lst
etc etc etc...
 

meanster99

Meum cerebrum nocet!
Local time
Today, 15:14
Joined
May 2, 2006
Messages
62
great advice mailman - I always follow that naming advice but never thought about it for modules!
 

Users who are viewing this thread

Top Bottom