ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   UserForm not passing Boolean variable (https://www.excelbanter.com/excel-programming/272079-re-userform-not-passing-boolean-variable.html)

Chip Pearson

UserForm not passing Boolean variable
 
Neal,

Since you're Unloading the user form, its properties all get set
back to the default value, False in the case of bQuit. Instead of
using Unload Me, use Me.Hide.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Neal Steiner" wrote in message
...
Dear experts,

I have the following code with regards to a
userform. If the user does not enter a value, he is
prompted with a question "if he wants to quit?". If he
hits Yes, I want the True value to be passed to the
overall sub. I am always getting false. What am I doing
wrong. Any help would be greatly appreciated. Thanks.

Neal

These items are in the Sheet code:

Public bQuit As Boolean

Private Sub CommandButton2_Click()
bQuit = False 'initialize bQuit
UserForm2.Show
If bQuit Then
MsgBox "True"
'more code here
Exit Sub
Else
MsgBox "False"
'other code here
End If

End Sub


And this is in the UserForm code:

Private Sub OKButton_Click()
If TextBox2.Text = "" Then
If MsgBox("Do you want to quit?", vbYesNo) = vbYes Then
bQuit = True
Unload UserForm2
Else
MsgBox "Please fix the value in the box"
TextBox2.SetFocus
End If
Else
Unload UserForm2
End If
End Sub





Oneide

UserForm not passing Boolean variable
 
Could "Option Explicit" help to solve it?


Tom Ogilvy escreveu nas notícias de
...
| Recall I said:
|
| In a general module at the top
|
| Public bQuit as Boolean
|
|
| It still needs to be in a general module. You can leave your other code
in
| the sheet module.
|
| Regards,
| Tom Ogilvy




Tom Ogilvy

UserForm not passing Boolean variable
 
Option Explicit would only signal that the variable isn't visible to the
userform when the declaration is in the sheet module. It would illuminate
the problem, but moving the declaration as stated would solve the problem.

--
Regards,
Tom Ogilvy

Oneide wrote in message
...
Could "Option Explicit" help to solve it?


Tom Ogilvy escreveu nas notícias de
...
| Recall I said:
|
| In a general module at the top
|
| Public bQuit as Boolean
|
|
| It still needs to be in a general module. You can leave your other code
in
| the sheet module.
|
| Regards,
| Tom Ogilvy







All times are GMT +1. The time now is 02:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com