How to reset global variables to nothing

P

Paul

In a form I store the value of the text box to the global variables in a
module. At some point I need to reset those variables in the module to
nothing. So I tried the following code in the form event, Set
GlobalVariable.Text1 = Nothing or GlobalVariable = vbNullString and both
does not work. Thanks.
 
A

Allen Browne

Unlike some languages, VB/VBA sets the initial value of the variable when
you declare it. Therefore the way to reset it depends on its type.

For numeric types (Integer, Long, Double, Currency, etc), just assign a
zero:
MyGlobal = 0

For String types, assign a zero-length string:
MyGlobal = vbNullString

For Variants, assign the value Empty:
MyGlobal = Empty

For objects (Form, Control, TextBox, Recordset, etc), set to Nothing:
Set MyGlobal = Nothing
 
P

Paul

How about if the variable is the "date" type??

Allen Browne said:
Unlike some languages, VB/VBA sets the initial value of the variable when
you declare it. Therefore the way to reset it depends on its type.

For numeric types (Integer, Long, Double, Currency, etc), just assign a
zero:
MyGlobal = 0

For String types, assign a zero-length string:
MyGlobal = vbNullString

For Variants, assign the value Empty:
MyGlobal = Empty

For objects (Form, Control, TextBox, Recordset, etc), set to Nothing:
Set MyGlobal = Nothing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top