ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Userform Question (https://www.excelbanter.com/excel-programming/325896-userform-question.html)

Ray Batig

Userform Question
 
Greetings,

I have a userform that changes the contents of the highlighted cell. I have
a message box routine which confirms that the desired cell is highlighted
(so we don't work on the wrong cell). At times, this gets laborous. What I
would like to do is add a checkbox to the userform. Then when you open the
workbook and run the userform you would go through the cell confirmation
question. Then, when the userform pops up, if you don't want to go through
the cell confirmation, you would check the checkbox. Once the checkbox is
checked, the programming would remember this until you uncheck the checkbox
or close the workbook.

I can do all of the programming, however, I need an easy way to have the
programming remember whether the checkbox is checked, and initially start
unchecked.

Any ideas on how to do this. In other languages there were volatile memory
variables which remained available until the program was shutdown. It
appears that these exist in VB, however, they only last while a module is
running.

Thanks for helping me understand!!

Ray



OJ[_2_]

Userform Question
 
Hi,
How about a global boolean variable that sets the value of the checkbox
on form loading and gets set by the checkbox on unloading? You could
set it in ThisWorkbook module (I think)....

Hth,
OJ


gocush[_29_]

Userform Question
 
In the ThisWorkbook module place it outside of any sub, and at the very top:

----------------------------------
Option Explicit

'Declare the variable Checked for use in all procedures:
Public Checked as Boolean
----------------------------------

Private sub.......................


"OJ" wrote:

Hi,
How about a global boolean variable that sets the value of the checkbox
on form loading and gets set by the checkbox on unloading? You could
set it in ThisWorkbook module (I think)....

Hth,
OJ



Bob Phillips[_6_]

Userform Question
 
Not ThisWorkbook, as that is a class module. Put it in a general code
module.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"OJ" wrote in message
oups.com...
Hi,
How about a global boolean variable that sets the value of the checkbox
on form loading and gets set by the checkbox on unloading? You could
set it in ThisWorkbook module (I think)....

Hth,
OJ




Bob Phillips[_6_]

Userform Question
 
You could also create a workbook name that holds the value

set it with
ActiveWorkbook.Names.Add name:="cbVal", RefersTo:=myVar1

get it with
myVar1 = Evaluate(ActiveWorkbook.Names("cbVal").RefersTo)


Or even more simply, never unload the form until the workbook closes, just
hide it, that way the checkbox value is maintained at all times.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Ray Batig" wrote in message
nk.net...
Greetings,

I have a userform that changes the contents of the highlighted cell. I

have
a message box routine which confirms that the desired cell is highlighted
(so we don't work on the wrong cell). At times, this gets laborous. What I
would like to do is add a checkbox to the userform. Then when you open the
workbook and run the userform you would go through the cell confirmation
question. Then, when the userform pops up, if you don't want to go through
the cell confirmation, you would check the checkbox. Once the checkbox is
checked, the programming would remember this until you uncheck the

checkbox
or close the workbook.

I can do all of the programming, however, I need an easy way to have the
programming remember whether the checkbox is checked, and initially start
unchecked.

Any ideas on how to do this. In other languages there were volatile memory
variables which remained available until the program was shutdown. It
appears that these exist in VB, however, they only last while a module is
running.

Thanks for helping me understand!!

Ray





Ray Batig

Userform Question
 
This worked fine. I found it best to create a new module and put the public
variables there. As you said, it doesn't work if you put the public
variables in the same module.

Thanks again!!

Bob Phillips wrote in message
...
Not ThisWorkbook, as that is a class module. Put it in a general code
module.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"OJ" wrote in message
oups.com...
Hi,
How about a global boolean variable that sets the value of the checkbox
on form loading and gets set by the checkbox on unloading? You could
set it in ThisWorkbook module (I think)....

Hth,
OJ







All times are GMT +1. The time now is 07:25 PM.

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