View Full Version : Solved: MsgBox problem
viper
11-14-2005, 01:04 PM
When I use this code I get the response for a yes answer even when no is clicked. What is wrong?
MsgBox "Do you want to find someone else? ", vbYesNo, ""
If vbYes Then
UserForm1.Show
Else
Exit Sub
End If
If I click no I still get the userform to show. This happens to me all the time and I get frustrated and use a second userform just to get the result I want.
Thanks for any advice, help, or beer!
malik641
11-14-2005, 01:07 PM
Hi Viper :hi: Welcome to the forums!
I can't explain why that is happening the way it is...and sorry I can't send ya any beer :giggle ...but try this:
Sub Userform()
If MsgBox("Do you want to find someone else? ", vbYesNo, "") = vbYes Then
UserForm1.Show
Else
Exit Sub
End If
End Sub
HTH
vonpookie
11-14-2005, 01:23 PM
Basically, you are selecting a response, but it is not connected to the values in the If statement at all. If that makes any sense (which it probably doesn't).
Malik's got the right idea, but I usually just use a variable, myself:
Dim ans As Variant
ans = MsgBox("Do you want to find someone else? ", vbYesNo)
If ans = vbYes Then
UserForm1.Show
Else
Exit Sub
End If
Killian
11-14-2005, 01:27 PM
Joesph's code is the way to go.
The reason being that MsgBox is a function that returns a value (depending on which button is clicked)
So you test the value the function throws back in the same line (in this case vbYes which is a xl constant - value: 6)... then do something
Hope that explains it :)
viper
11-14-2005, 01:28 PM
Thanks each of you. I understand now. Never stop learning, everyday is a learning experience at some level.
sheeeng
11-15-2005, 02:43 AM
Joesph's code is the way to go.
The reason being that MsgBox is a function that returns a value (depending on which button is clicked)
So you test the value the function throws back in the same line (in this case vbYes which is a xl constant - value: 6)... then do something
Hope that explains it :)
Hello Viper! Welcome to VBAX! :hi:
Support Joseph idea here. :friends:
malik641
11-15-2005, 06:36 AM
Joesph's code is the way to go.
Support Joseph idea here. :friends:
:beerchug: Thanks for the support guys!:beerchug:
Thanks each of you. I understand now. Never stop learning, everyday is a learning experience at some level.
:friends: Glad to help! And no, never stop learning :thumb
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.