Msg Box with Yes and No options

Addie

Registered User.
Local time
Today, 13:01
Joined
Aug 27, 2008
Messages
12
Hello Everyone,

Can anyone please help me out in how to create a mesage box with Yes and No buttons and then how to select that what button the user has selected (yes or no) Please help its urgent.
Thanks.

Regards,
Addie
 
I don't think I could describe it better than Access help.

Brian
 
Code:
Dim x As Integer
    x = MsgBox("stuff", vbYesNo)
    If x = vbYes Then
        DoSomething
    Else
        DoSomethingElse
    End If
 
Thanks a lot Gregg for a quick reply. I am new to Access to facing difficulties but will learn fast.
 
Sorry I mean George. Sorry for the mistake. Thanks.
 
Sorry I mean George. Sorry for the mistake. Thanks. Aditi
 
Just an add on example:
If MsgBox("You can put more than one line in the message" & vbNewLine & "to make the message clearer",vbYesNo,"And this will put a title on the top.") = vbYes then
 
Smiles. I was part of the Microsoft Access Beta and still have the 5 1/2" flopiess. No drive for them unfortunately. I am new to forums. Hopefully I wont mess up too much.
 
msgbox is pretty powerful - use vb constants and you cant go too wrong

so you get

if msgbox("my question",vbyesno) = vbno then
'code for answering no goes here
else
'code for answering yes goes here
end if

you can also use vbokcancel, to give buttons called not surprisingly ok, or cancel, if you want them instead of yes or no

if msgbox("my question",vbokcancel) = vbno then


you can also change the default button, so that


if msgbox("my question",vbyesno+vbdefaultbutton2) = vbno then

will highlight no, as the default rather than yes.

---------
You can also add a symbol in the msgbox by adding vbquestion, vbexclamation or vbinformation

eg
if msgbox("my question",vbyesno+vbdefaultbutton2+vbquestion) = vbno then

-------
there are numerous other switches - the only thing you can't do in a msgbox is add your own named buttons, which certainly would be helpful at times.
 
You have all given Addie lots of info, but isn't it all, except Magicman's, clearly laid out in Help?
Shouldn't we be encouraging posters to use help and think for themselves when help has the info, especially as a starting point.

Brian
 
In General, I agree. In some cases, the Microsoft help assumes the reader has basic knowledge that is not included in the search results. For example the constants like vbYesNo, vbNewLine when entered in the help return no hits. Try using help to find the Dim statement and a description of string. Try finding a reasonable description of an object versus a control, and why the access default is to have the object name = the control name to ensure you stay confused. Many times, the answer is in the Help if I could remember that it only applies under a specific condition, which is not identified in the help. So after many visits by Beginners to the Help with tons of frustration, I can see why they ask simple questions here.
 
I remember when I was an Access noob with a ton of VB and Oracle experience. It was a very frustrating experience and help was useless.

I don't mind spending 30 seconds to help out, even if I copy it from the help file.
 
I agree that in general microsoft's help is bad and getting worse, with its examples poor and search useless, however in the case of Msgabox the original question is answered and there is info on eg vbYesNo, although not vbNewline.

Brian
 
My point was to show how to do multiple lines. I could have added the (undocumented in help)...bold text as well, but that would have been overload.
Smiles
PS: Do not give up on help.....I find many answers there, and the Northwinds sample database. (I would not code like it is done in Northwinds....fancy, complicated with gimmicks and shortcuts that allow for future lack of understanding and failures...Keep It Simple Stupid (KISS)) The answers on the whole are there in the help, tutorials, and the sample database....most people do not take the day or two to read through it all, not once but twice...instead they take a week or two searching the web and trying things that don't help.
Smiles
Bob ...
 

Users who are viewing this thread

Back
Top Bottom