Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set a variable equal to Null

Status
Not open for further replies.

grnzbra

Programmer
Mar 12, 2002
1,273
US
I have code:

'define global variable
Public TstIntgr as Long


Elewhere, I have code:

TstIntgr = -1

I would like, now, after having set it to -1, make it null

TstIntgr = Null

does not work. Just how does one go about setting a variable equal to Null?
 
As far as I know you cannot assign Null to a Long variable.
You need a Variant type variable which supports the Null condition.

Simmsey
 
What is it you are trying to do? Do you really have a need for a global variable? If you stored that field, you can assign a null to it thru a query. Melissa
Designing Access databases since 1999
 
Melissa,
What do you mean by "stored that field"?
 
If you stored it in a table rather than using a global variable, you can use a query to change a number field to null. Of course, I don't know what it is you are trying to do, so storing that variable may not even makes any sense for your purpose. My point is that you can change any field type to a null thru a query, I just don't know how to do it in code, (other than for a string type). Melissa
Designing Access databases since 1999
 
As mentioned by simmsey, make the global a variant and it can be set to null with code. just tried it and it works.
I can't see createing a table for a temporary variable.

The object of the exercise was to answer the question about how to get a check box to give selected records on a checked condition and all records on an unchecked condition (selecting on a true/false field)
 
Only warning is that Variant data types require more storage space.

grnzbra your explanation for the need to set a variable to Null has me a little confused.

I assumed you needed to represent a Long value (any + or - value within range of a Long) as well as represent when no value is assigned. (i.e. Null)

If all you need is to represent checked and unchecked shouldnt you use a Boolean variable?

Simmsey
 
No, in that case, if the criteria for the yes/no field is equal to the checkbox, he will get only the true records when the checkbox is checked and only the false records when the checkbox is unchecked. What he wants is the true records when the checkbox is checked and all the records when the checkbox is unchecked. The solution is a function as a variant which equals "*" if the checkbox is not checked, and -1 if the checkbox is checked. The criteria for the query is set to Like the funcion so it comes out either Like -1 or Like "*". I've tried it and it does work (By setting the Triple State property of the checkbox to True, he can make the selection of any one of the three, True records, False Records and All records.)
In the process of trying to create a solution, I attempted to set a variable to null and this prompted my question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top