PDA

View Full Version : Solved: Rename Message Box Buttons



CreganTur
03-07-2008, 12:19 PM
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.


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



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

Any way to do this?

Carl A
03-09-2008, 05:56 AM
Just use a form for a custom message box

CreganTur
03-10-2008, 06:25 AM
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.

orange
03-10-2008, 06:39 AM
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

DarkSprout
03-10-2008, 05:47 PM
I've built you this Example for a Custom Message Box
It uses a Class to do the donkey work:

e.g.
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
Now you can have any button text you like.

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

=DarkSprout=

Trevor
03-10-2008, 05:59 PM
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

orange
03-10-2008, 07:15 PM
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.

Trevor
03-10-2008, 09:54 PM
sorry , I missed his post when I was posting, I see it now :-p thanks

CreganTur
03-11-2008, 06:48 AM
Thanks Darksprout- exactly what I was looking for!

Carl A
03-11-2008, 07:49 AM
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?

DarkSprout
03-11-2008, 09:59 AM
Error - See Next...:banghead:

DarkSprout
03-11-2008, 10:01 AM
The ClickEvent sends a numeric parameter (1,2,3) to a Sub called Response

Change these to an OnClick Event
eg.

Private Sub cmbd1_Click()
Call Response(1)
End Sub

And the Same for cmbd2 and cmbd3 - sending 2 or 3.

Hope this helps,
=DarkSprout=

whassan
03-31-2008, 04:32 AM
Hi.
If I want the button1 open the form1
and button2 open the form2
how can I do it ?
thank you

whassan
03-31-2008, 04:35 AM
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

DarkSprout
03-31-2008, 12:00 PM
To use the example I supplied above:


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

yabrahamson
03-06-2016, 06:03 PM
Would you mind attaching the class module for this? I can't find it in the thread.

Thanks.

hima193
02-18-2019, 01:12 PM
To use the example I supplied above:


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

i tried to use it but i get compile error on cls_MessageBox

i dont know where is the proble

orange
02-18-2019, 01:32 PM
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.

phplab23
03-18-2019, 03:54 AM
thanx for sharing this article.is most important when user is create account in website.