How do I change button text in message box?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Using Access 2000, I would like to use the message box to perform one of 2
functions or cancel. I could build my own form, but that seems tedious as I
have quite a few locations where I would like to do this, but the details
would be different for each situation. I am currently using the
Yes/No/Cancel message box option. It's just the Yes and No option are
somewhat confusing. I use the text to explain what will happen with yes vs.
no or cancel, but it is not as intuitive as being able to change the word Yes
or No on the button.
 
Using Access 2000, I would like to use the message box to perform one of 2
functions or cancel. I could build my own form, but that seems tedious as I
have quite a few locations where I would like to do this, but the details
would be different for each situation. I am currently using the
Yes/No/Cancel message box option. It's just the Yes and No option are
somewhat confusing. I use the text to explain what will happen with yes vs.
no or cancel, but it is not as intuitive as being able to change the word Yes
or No on the button.

The possible text on message box command buttons is limited to just
those offered in Intellisense when you are writing the msgbox code,
i.e. vbYes/No Cancel, vbYesNo, vbOKOnly, vbRetryCancel, etc.

You'll have to take the tedious route and create your own message
form.
 
You could design one custom form and make it look like a message box. Have
a label for the prompt string and however many buttons you want. Program
the buttons to set a public variable to equal their caption when clicked,
and save the form (I called my test form "frmMyMessage"). Create a Sub in a
standard module that will open this form and set the label text, button text
and form caption to whatever you pass to the sub as arguments. Whenever you
want to use (and re-use) this form, just call the function with the
arguments you want to appear on the form. It might not be an elegant
solution, but it might give you some ideas. Here's some sample code for
each piece you need (what out for line-wrapping):

'*********frmMyMessage events for the three buttons*******
Option Compare Database
Option Explicit

Private Sub cmd1_Click()
strClicked = cmd1.Caption
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub

Private Sub cmd2_Click()
strClicked = cmd2.Caption
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub

Private Sub cmd3_Click()
strClicked = cmd3.Caption
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub
'***********************

'*****Global Sub in a Standard Module*********
Option Compare Database
Option Explicit
Public strClicked As String

Function MyMessageBox(TheCaption As String, ThePrompt As String, _
Button1 As String, Button2 As String, Button3 As String)
DoCmd.OpenForm "frmMyMessage", acDesign, , , , acHidden
With Forms!frmMyMessage
.Caption = TheCaption
.lblPrompt.Caption = ThePrompt
.cmd1.Caption = Button1
.cmd2.Caption = Button2
.cmd3.Caption = Button3
End With
DoCmd.Close acForm, "frmMyMessage", acSaveYes
DoCmd.OpenForm "frmMyMessage", , , , , acDialog
MyMessageBox = strClicked
End Function
'*********************

'****Command button (for testing) on a form********
Private Sub Command1_Click()
Dim strCaption As String, strPrompt As String, strResult As String

strCaption = "Testing Only"
strPrompt = "Please select 'Ok' to continue, 'Close' to close, " _
& "or 'Ignore This' to do nothing"
strResult = MyMessageBox(strCaption, strPrompt, "Ok", "Close", "Ignore
This")
Select Case strResult
Case "Ok"
'whatever you want when 'Ok' is clicked
Case "Close"
'whatever you want when 'Close' is clicked
Case "Ignore This"
'whatever you want when 'Ignore This' is clicked
End Select

End Sub
'**********************
 
Back
Top