View Full Version : Solved: Boolean Working?
Could someone please check the following boolean code and see if it is working properly on your computer. It is resulting in FALSE for me regardless of which button I click.
delOriginal = MsgBox(Prompt:="Delele the original forwarded email? ", _
Buttons:=vbYesNo, Title:="Delete Original Contact?")
If delOriginal = vbYes Then
MsgBox "TRUE"
Else: MsgBox "FALSE"
End If
Bob Phillips
05-01-2011, 03:28 PM
Works fine for me, XL2007, XP pro.
Thanks. That's odd that it works for you. I'm in Outlook 2000 and it's reporting FALSE for both the Yes and No buttons.
I just tried it in a new clean module, with no other code, and it works for me. For some reason, there is something in my broader script that is causing it to misfire.
mikerickson
05-01-2011, 08:54 PM
What is delOriginal dimensioned as?
What is delOriginal dimensioned as?
Boolean.
Sub delOriginal()
Dim delOriginal As Boolean
delOriginal = MsgBox(Prompt:="Delele the original forwarded email? ", _
Buttons:=vbYesNo, Title:="Delete Original Email?")
If delOriginal = True Then
MsgBox "True"
Else: MsgBox "False"
End If
End Sub
I restructured the code as follows and it seems to work fine now.
Sub delOriginal()
Dim myPrompt As String
myPrompt = "Do you want to delete the original forwarded email? "
If MsgBox(prompt:=myPrompt, _
Buttons:=vbYesNo, Title:="Delete Original Email?") = vbYes Then
MsgBox "True"
Else: MsgBox "False"
End If
End Sub
mikerickson
05-02-2011, 11:58 AM
The value returned from a message box is data type Long, not Boolean.
Change one line from the original code and all will be well
Sub delOriginal()
Dim delOriginal As Long
delOriginal = MsgBox(Prompt:="Delele the original forwarded email? ", _
Buttons:=vbYesNo, Title:="Delete Original Email?")
If delOriginal = True Then
MsgBox "True"
Else: MsgBox "False"
End If
End Sub
The value returned from a message box is data type Long, not Boolean.
Change one line from the original code and all will be well
Sub delOriginal()
Dim delOriginal As Long
delOriginal = MsgBox(Prompt:="Delele the original forwarded email? ", _
Buttons:=vbYesNo, Title:="Delete Original Email?")
If delOriginal = True Then
MsgBox "True"
Else: MsgBox "False"
End If
End Sub
Thanks. I'm glad you cleared that up. It was driving me crazy.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.