Messagebox Help


Posted by Jason A on January 07, 2002 2:32 PM

I want to use a vbYesNo messagebox, but are having trouble with the code. What is the code if the user selects Yes (runs a macro) and if the user selects No it closes the messagebox.

Thanks

Posted by Scott on January 07, 2002 2:40 PM

Try this:

If MsgBox("Test", vbYesNo, "Title") = vbYes Then
'Enter code for selection yes
Else
'Enter code for selection no or use Exit Sub
End If

Posted by Jacob on January 07, 2002 3:27 PM

Hi

Dim Answer as vbmessageboxresult

answer = msgbox("What do know what you want to do?,vbyesno,"Title"

select case answer

case vbyes
your code here
case vbno
your code here

this code will work with more buttons as well like abort/retry/cancel, just add another case.

HTH

Jacob

Posted by Qroozn on January 07, 2002 3:53 PM

Jacob re: Dim

Jacob. How much dif does a dim make to the speed of the application. I have made a huge program. but have no dims because i have never understood how important their functionality was. the program is full of macros.



Posted by Jacob on January 07, 2002 4:57 PM

Re: Jacob re: Dim

Hi

Check out the help on data types. If the type isnt specified then it is a variant which used more memory. since it has to be able to accept every type of value. If you specify what it is like date, integer etc. Then it uses less memory. In practivle terms I dont think it matters, but it is a good practice anyways. When debugging your program or going back to modify them months later you may not remember what the variable do, so you have to take more time going through code. Also you should use option explicit at the top of your modules to force yourself to declare variables this will prevent errors on mispelled variable. For example: If you have Myvalue = this+that and later on in the code you put Myvalu it will be 0 since myvalu doesnt equal anything, but with option explicit it would give you the error undefined variable and show you the variable so you can fix the problem immediately.

HTH

Jacob