Help with yes / no box or OK / Cancel box

wolfwrz

New member
Local time
Today, 14:50
Joined
Jul 3, 2003
Messages
8
I have a command button that I want to display a warning before it functions. I want it to pop up a are you sure warning. then proccess only if the yes/ok is pressed or exit function if cancel/no is pressed.

Thanks in advance
 
From the help file: search for "MsgBox Function"


MsgBox Function Example
This example uses the MsgBox function to display a critical-error message in a dialog box with Yes and No buttons. The No button is specified as the default response. The value returned by the MsgBox function depends on the button chosen by the user. This example assumes that DEMO.HLP is a Help file that contains a topic with a Help context number equal to 1000.

Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Do you want to continue ?" ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "MsgBox Demonstration" ' Define title.
Help = "DEMO.HLP" ' Define Help file.
Ctxt = 1000 ' Define topic
' context.
' Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' User chose Yes.
MyString = "Yes" ' Perform some action.
Else ' User chose No.
MyString = "No" ' Perform some action.
End If

Actually this "Help" isn't very helpful, but it should point you in the right direction. Also you will need to change "Style = vbYesNo" to "Style = vbYesNoCancel"
 
Tony Hine's post will work, but being an anal programmer, I would rather see those variables dim'd using variable types instead of allowing them to all be variant types. This saves memory and speed execution. I know, it probably won't make a difference in code like this, just my 2 cents...

Here's my anal version:

Sub MsgBoxExample()
Dim strMsg As String
Dim intStyle As Integer
Dim strTitle As String
Dim intResponse As Integer
Dim strMyString As String

 strMsg = "Do you want to continue ?" ' Define message.
 intStyle = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
 strTitle = "MsgBox Demonstration" ' Define title.

 ' Display message.
 intResponse = MsgBox(strMsg, intStyle, strTitle)

 If intResponse = vbYes Then ' User chose Yes.
  strMyString = "Yes" ' Perform some action.
 Else ' User chose No.
  strMyString = "No" ' Perform some action.
 End If

End Sub
 

Users who are viewing this thread

Back
Top Bottom