Consulting

Results 1 to 19 of 19

Thread: Solved: Rename Message Box Buttons

  1. #1
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location

    Question Solved: Rename Message Box Buttons

    I'm using VBA and Access to do some automation stuff. I've got a few message boxes, like this one, where I list options in text and tell the User which button to press for the option.

    [vba]
    Function MessageBox()
    MsgBox "What do you want to do next?" & _
    vbCrLf & vbCrLf & "Press OK to print report" & _
    vbCrLf & vbCrLf & "Press Cancel to quit", vbInformation + vbOKCancel, "Print or Quit?"

    End Function

    [/vba]

    I would prefer to just rename the buttons on the message box so that:
    OK = Print Report
    Cancel = Quit

    Any way to do this?

  2. #2
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    220
    Location
    Just use a form for a custom message box
    "Intellectual passion occurs at the intersection of fact and implication."

    SGB

  3. #3
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    Quote Originally Posted by Carl A
    Just use a form for a custom message box
    I know that I can use a form for this. I'm just curious to know if it is possible to rename the buttons on a message box.

  4. #4
    VBAX Tutor
    Joined
    Nov 2007
    Posts
    257
    Location
    Quote Originally Posted by CreganTur
    I know that I can use a form for this. I'm just curious to know if it is possible to rename the buttons on a message box.
    I don't think you can rename the buttons on a message box, but here is a great link for forms and samples.
    http://www.fontstuff.com/access/acctut20.htm

  5. #5
    VBAX Contributor DarkSprout's Avatar
    Joined
    Oct 2007
    Location
    Essex, England
    Posts
    144
    Location

    Custom Messgae Box

    I've built you this Example for a Custom Message Box
    It uses a Class to do the donkey work:

    e.g.
    [vba]Public Function TestMyMessageBox() As Integer

    Set MyMsgBox = New cls_MessageBox
    With MyMsgBox
    '// you can have any combinations of buttons(up to 3!)
    .Button1Text = "Print Report"
    .Button2Text = "Quit"
    '.Button3Text = "3rd Button" '// not used here
    .BoxStyle = Information
    .Prompt = "Testing my MyMsgBox"
    .Title = "Title here"
    End With
    TestMyMessageBox= MyMsgBox.MessageBox '// Loads MessageBox

    End Function[/vba]
    Now you can have any button text you like.

    the return is the button number(read: Left to Right).
    Enjoy,

    =DarkSprout=
    =|)arkSprout=
    VBA | VBScript | C# Programmer

    "Give a person a fish and you feed them for a day; teach a person to use the Internet and they won't bother you for weeks."

  6. #6
    VBAX Mentor
    Joined
    Dec 2007
    Posts
    462
    Location
    unfortunity you cannot rename the button for message boxes, I've searched and tried myself and found that you are stuck with : vbok, vbokonly, vbyesno,vbyesnocancle ( and vbdefalt, 1 ,2, 3 witch is the same as above, but your stuck with buttons, yes, no, ok, cancel , you will havd to use a make a form based apon what responce you are looking for
    ie: dim responce as string
    responce = msg(" msg here")
    if responce = vb yes Then
    [Contition]
    else [condition]
    End if
    end sub

  7. #7
    VBAX Tutor
    Joined
    Nov 2007
    Posts
    257
    Location
    Quote Originally Posted by CreganTur
    I know that I can use a form for this. I'm just curious to know if it is possible to rename the buttons on a message box.
    See the message from DarkSprout. He created a class module that will allow you to have customized buttons, title etc.
    Download his sample database; copy his class module, then set up your usage to use his class module substituting your values for his sample values that he showed in his post.

  8. #8
    VBAX Mentor
    Joined
    Dec 2007
    Posts
    462
    Location
    sorry , I missed his post when I was posting, I see it now :-p thanks

  9. #9
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    Thanks Darksprout- exactly what I was looking for!

  10. #10
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    220
    Location
    Quote Originally Posted by DarkSprout
    I've built you this Example for a Custom Message Box
    It uses a Class to do the donkey work:
    =DarkSprout=
    Works fine in Access 2000, however it totally pukes in 2007. I can't tell you what the problem is because the only option I'm left with after clicking either button is to use Windows Task Manager to shut Access down. I put a break in the code and that doesn't even work.

    The Error is The Expression OnClick you entered as the event property setting Produced the following Error: The expresssion you entered has a function name that Microsoft Office Access can't find.
    Any Ideas?
    "Intellectual passion occurs at the intersection of fact and implication."

    SGB

  11. #11
    VBAX Contributor DarkSprout's Avatar
    Joined
    Oct 2007
    Location
    Essex, England
    Posts
    144
    Location
    Error - See Next...
    =|)arkSprout=
    VBA | VBScript | C# Programmer

    "Give a person a fish and you feed them for a day; teach a person to use the Internet and they won't bother you for weeks."

  12. #12
    VBAX Contributor DarkSprout's Avatar
    Joined
    Oct 2007
    Location
    Essex, England
    Posts
    144
    Location
    The ClickEvent sends a numeric parameter (1,2,3) to a Sub called Response

    Change these to an OnClick Event
    eg.
    [vba]
    Private Sub cmbd1_Click()
    Call Response(1)
    End Sub
    [/vba]
    And the Same for cmbd2 and cmbd3 - sending 2 or 3.

    Hope this helps,
    =DarkSprout=
    =|)arkSprout=
    VBA | VBScript | C# Programmer

    "Give a person a fish and you feed them for a day; teach a person to use the Internet and they won't bother you for weeks."

  13. #13
    Hi.
    If I want the button1 open the form1
    and button2 open the form2
    how can I do it ?
    thank you

  14. #14
    Hi DarkSprout,
    If I want the Cmbd1 open the form1
    and Cmbd2 open the form2, and Cmbd3 exit
    how can I do it ?
    thank you

  15. #15
    VBAX Contributor DarkSprout's Avatar
    Joined
    Oct 2007
    Location
    Essex, England
    Posts
    144
    Location
    To use the example I supplied above:

    [vba]
    Public Function TestMyMessageBox()
    Dim nResult As Integer
    Set MyMsgBox = New cls_MessageBox
    With MyMsgBox
    '// you can have any combinations of buttons(up to 3!)
    .Button1Text = "Print Report"
    .Button2Text = "Quit"
    '.Button3Text = "3rd Button" '// not used here
    .BoxStyle = Information
    .Prompt = "Testing my MyMsgBox"
    .Title = "Title here"
    End With
    nResult = MyMsgBox.MessageBox '// Loads MessageBox

    Select Case nResult
    Case 1:
    DoCmd.OpenForm "frm_Form1"
    Case 2:
    DoCmd.OpenForm "frm_Form2"
    Case 3:
    DoCmd.Close
    End Select
    End Function[/vba]
    =|)arkSprout=
    VBA | VBScript | C# Programmer

    "Give a person a fish and you feed them for a day; teach a person to use the Internet and they won't bother you for weeks."

  16. #16
    Would you mind attaching the class module for this? I can't find it in the thread.

    Thanks.

  17. #17
    VBAX Newbie
    Joined
    Feb 2019
    Posts
    1
    Location
    Quote Originally Posted by DarkSprout View Post
    To use the example I supplied above:

    [vba]
    Public Function TestMyMessageBox()
    Dim nResult As Integer
    Set MyMsgBox = New cls_MessageBox
    With MyMsgBox
    '// you can have any combinations of buttons(up to 3!)
    .Button1Text = "Print Report"
    .Button2Text = "Quit"
    '.Button3Text = "3rd Button" '// not used here
    .BoxStyle = Information
    .Prompt = "Testing my MyMsgBox"
    .Title = "Title here"
    End With
    nResult = MyMsgBox.MessageBox '// Loads MessageBox

    Select Case nResult
    Case 1:
    DoCmd.OpenForm "frm_Form1"
    Case 2:
    DoCmd.OpenForm "frm_Form2"
    Case 3:
    DoCmd.Close
    End Select
    End Function[/vba]
    i tried to use it but i get compile error on cls_MessageBox

    i dont know where is the proble

  18. #18
    VBAX Tutor
    Joined
    Nov 2007
    Posts
    257
    Location
    Quote Originally Posted by hima193 View Post
    i tried to use it but i get compile error on cls_MessageBox

    i dont know where is the proble
    I think that somewhere over the years since this post was started Darksprout has removed the code for his class module.
    If he happens to pass by he may post a copy.
    You may find something via google or bing.

  19. #19
    VBAX Newbie
    Joined
    Feb 2019
    Location
    harihar chowk
    Posts
    1
    Location
    thanx for sharing this article.is most important when user is create account in website.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •